10b57cec5SDimitry Andric //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file declares LLVMContextImpl, the opaque implementation 100b57cec5SDimitry Andric // of LLVMContext. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H 150b57cec5SDimitry Andric #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H 160b57cec5SDimitry Andric 170b57cec5SDimitry Andric #include "ConstantsContext.h" 180b57cec5SDimitry Andric #include "llvm/ADT/APFloat.h" 190b57cec5SDimitry Andric #include "llvm/ADT/APInt.h" 200b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h" 210b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h" 220b57cec5SDimitry Andric #include "llvm/ADT/DenseMapInfo.h" 230b57cec5SDimitry Andric #include "llvm/ADT/DenseSet.h" 240b57cec5SDimitry Andric #include "llvm/ADT/FoldingSet.h" 250b57cec5SDimitry Andric #include "llvm/ADT/Hashing.h" 260b57cec5SDimitry Andric #include "llvm/ADT/STLExtras.h" 270b57cec5SDimitry Andric #include "llvm/ADT/SmallPtrSet.h" 280b57cec5SDimitry Andric #include "llvm/ADT/SmallVector.h" 290b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h" 300b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h" 310b57cec5SDimitry Andric #include "llvm/IR/Constants.h" 320b57cec5SDimitry Andric #include "llvm/IR/DebugInfoMetadata.h" 330b57cec5SDimitry Andric #include "llvm/IR/DerivedTypes.h" 340b57cec5SDimitry Andric #include "llvm/IR/LLVMContext.h" 350b57cec5SDimitry Andric #include "llvm/IR/Metadata.h" 361fd87a68SDimitry Andric #include "llvm/IR/Module.h" 370b57cec5SDimitry Andric #include "llvm/IR/TrackingMDRef.h" 381fd87a68SDimitry Andric #include "llvm/IR/Type.h" 391fd87a68SDimitry Andric #include "llvm/IR/Value.h" 400b57cec5SDimitry Andric #include "llvm/Support/Allocator.h" 410b57cec5SDimitry Andric #include "llvm/Support/Casting.h" 420b57cec5SDimitry Andric #include "llvm/Support/StringSaver.h" 430b57cec5SDimitry Andric #include <algorithm> 440b57cec5SDimitry Andric #include <cassert> 450b57cec5SDimitry Andric #include <cstddef> 460b57cec5SDimitry Andric #include <cstdint> 470b57cec5SDimitry Andric #include <memory> 48bdd1243dSDimitry Andric #include <optional> 490b57cec5SDimitry Andric #include <string> 500b57cec5SDimitry Andric #include <utility> 510b57cec5SDimitry Andric #include <vector> 520b57cec5SDimitry Andric 530b57cec5SDimitry Andric namespace llvm { 540b57cec5SDimitry Andric 551fd87a68SDimitry Andric class AttributeImpl; 561fd87a68SDimitry Andric class AttributeListImpl; 571fd87a68SDimitry Andric class AttributeSetNode; 581fd87a68SDimitry Andric class BasicBlock; 591fd87a68SDimitry Andric struct DiagnosticHandler; 60*5f757f3fSDimitry Andric class DPMarker; 611fd87a68SDimitry Andric class ElementCount; 621fd87a68SDimitry Andric class Function; 631fd87a68SDimitry Andric class GlobalObject; 641fd87a68SDimitry Andric class GlobalValue; 651fd87a68SDimitry Andric class InlineAsm; 661fd87a68SDimitry Andric class LLVMRemarkStreamer; 671fd87a68SDimitry Andric class OptPassGate; 681fd87a68SDimitry Andric namespace remarks { 691fd87a68SDimitry Andric class RemarkStreamer; 701fd87a68SDimitry Andric } 711fd87a68SDimitry Andric template <typename T> class StringMapEntry; 725ffd83dbSDimitry Andric class StringRef; 73bdd1243dSDimitry Andric class TypedPointerType; 740b57cec5SDimitry Andric class ValueHandleBase; 750b57cec5SDimitry Andric 76*5f757f3fSDimitry Andric template <> struct DenseMapInfo<APFloat> { 770b57cec5SDimitry Andric static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); } 78349cc55cSDimitry Andric static inline APFloat getTombstoneKey() { 79349cc55cSDimitry Andric return APFloat(APFloat::Bogus(), 2); 80349cc55cSDimitry Andric } 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric static unsigned getHashValue(const APFloat &Key) { 830b57cec5SDimitry Andric return static_cast<unsigned>(hash_value(Key)); 840b57cec5SDimitry Andric } 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric static bool isEqual(const APFloat &LHS, const APFloat &RHS) { 870b57cec5SDimitry Andric return LHS.bitwiseIsEqual(RHS); 880b57cec5SDimitry Andric } 890b57cec5SDimitry Andric }; 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric struct AnonStructTypeKeyInfo { 920b57cec5SDimitry Andric struct KeyTy { 930b57cec5SDimitry Andric ArrayRef<Type *> ETypes; 940b57cec5SDimitry Andric bool isPacked; 950b57cec5SDimitry Andric 96349cc55cSDimitry Andric KeyTy(const ArrayRef<Type *> &E, bool P) : ETypes(E), isPacked(P) {} 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric KeyTy(const StructType *ST) 990b57cec5SDimitry Andric : ETypes(ST->elements()), isPacked(ST->isPacked()) {} 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andric bool operator==(const KeyTy &that) const { 1020b57cec5SDimitry Andric if (isPacked != that.isPacked) 1030b57cec5SDimitry Andric return false; 1040b57cec5SDimitry Andric if (ETypes != that.ETypes) 1050b57cec5SDimitry Andric return false; 1060b57cec5SDimitry Andric return true; 1070b57cec5SDimitry Andric } 108349cc55cSDimitry Andric bool operator!=(const KeyTy &that) const { return !this->operator==(that); } 1090b57cec5SDimitry Andric }; 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric static inline StructType *getEmptyKey() { 1120b57cec5SDimitry Andric return DenseMapInfo<StructType *>::getEmptyKey(); 1130b57cec5SDimitry Andric } 1140b57cec5SDimitry Andric 1150b57cec5SDimitry Andric static inline StructType *getTombstoneKey() { 1160b57cec5SDimitry Andric return DenseMapInfo<StructType *>::getTombstoneKey(); 1170b57cec5SDimitry Andric } 1180b57cec5SDimitry Andric 1190b57cec5SDimitry Andric static unsigned getHashValue(const KeyTy &Key) { 120349cc55cSDimitry Andric return hash_combine( 121349cc55cSDimitry Andric hash_combine_range(Key.ETypes.begin(), Key.ETypes.end()), Key.isPacked); 1220b57cec5SDimitry Andric } 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric static unsigned getHashValue(const StructType *ST) { 1250b57cec5SDimitry Andric return getHashValue(KeyTy(ST)); 1260b57cec5SDimitry Andric } 1270b57cec5SDimitry Andric 1280b57cec5SDimitry Andric static bool isEqual(const KeyTy &LHS, const StructType *RHS) { 1290b57cec5SDimitry Andric if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 1300b57cec5SDimitry Andric return false; 1310b57cec5SDimitry Andric return LHS == KeyTy(RHS); 1320b57cec5SDimitry Andric } 1330b57cec5SDimitry Andric 1340b57cec5SDimitry Andric static bool isEqual(const StructType *LHS, const StructType *RHS) { 1350b57cec5SDimitry Andric return LHS == RHS; 1360b57cec5SDimitry Andric } 1370b57cec5SDimitry Andric }; 1380b57cec5SDimitry Andric 1390b57cec5SDimitry Andric struct FunctionTypeKeyInfo { 1400b57cec5SDimitry Andric struct KeyTy { 1410b57cec5SDimitry Andric const Type *ReturnType; 1420b57cec5SDimitry Andric ArrayRef<Type *> Params; 1430b57cec5SDimitry Andric bool isVarArg; 1440b57cec5SDimitry Andric 145349cc55cSDimitry Andric KeyTy(const Type *R, const ArrayRef<Type *> &P, bool V) 146349cc55cSDimitry Andric : ReturnType(R), Params(P), isVarArg(V) {} 1470b57cec5SDimitry Andric KeyTy(const FunctionType *FT) 1480b57cec5SDimitry Andric : ReturnType(FT->getReturnType()), Params(FT->params()), 1490b57cec5SDimitry Andric isVarArg(FT->isVarArg()) {} 1500b57cec5SDimitry Andric 1510b57cec5SDimitry Andric bool operator==(const KeyTy &that) const { 1520b57cec5SDimitry Andric if (ReturnType != that.ReturnType) 1530b57cec5SDimitry Andric return false; 1540b57cec5SDimitry Andric if (isVarArg != that.isVarArg) 1550b57cec5SDimitry Andric return false; 1560b57cec5SDimitry Andric if (Params != that.Params) 1570b57cec5SDimitry Andric return false; 1580b57cec5SDimitry Andric return true; 1590b57cec5SDimitry Andric } 160349cc55cSDimitry Andric bool operator!=(const KeyTy &that) const { return !this->operator==(that); } 1610b57cec5SDimitry Andric }; 1620b57cec5SDimitry Andric 1630b57cec5SDimitry Andric static inline FunctionType *getEmptyKey() { 1640b57cec5SDimitry Andric return DenseMapInfo<FunctionType *>::getEmptyKey(); 1650b57cec5SDimitry Andric } 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric static inline FunctionType *getTombstoneKey() { 1680b57cec5SDimitry Andric return DenseMapInfo<FunctionType *>::getTombstoneKey(); 1690b57cec5SDimitry Andric } 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric static unsigned getHashValue(const KeyTy &Key) { 172349cc55cSDimitry Andric return hash_combine( 173349cc55cSDimitry Andric Key.ReturnType, 174349cc55cSDimitry Andric hash_combine_range(Key.Params.begin(), Key.Params.end()), Key.isVarArg); 1750b57cec5SDimitry Andric } 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric static unsigned getHashValue(const FunctionType *FT) { 1780b57cec5SDimitry Andric return getHashValue(KeyTy(FT)); 1790b57cec5SDimitry Andric } 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric static bool isEqual(const KeyTy &LHS, const FunctionType *RHS) { 1820b57cec5SDimitry Andric if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 1830b57cec5SDimitry Andric return false; 1840b57cec5SDimitry Andric return LHS == KeyTy(RHS); 1850b57cec5SDimitry Andric } 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { 1880b57cec5SDimitry Andric return LHS == RHS; 1890b57cec5SDimitry Andric } 1900b57cec5SDimitry Andric }; 1910b57cec5SDimitry Andric 192bdd1243dSDimitry Andric struct TargetExtTypeKeyInfo { 193bdd1243dSDimitry Andric struct KeyTy { 194bdd1243dSDimitry Andric StringRef Name; 195bdd1243dSDimitry Andric ArrayRef<Type *> TypeParams; 196bdd1243dSDimitry Andric ArrayRef<unsigned> IntParams; 197bdd1243dSDimitry Andric 198bdd1243dSDimitry Andric KeyTy(StringRef N, const ArrayRef<Type *> &TP, const ArrayRef<unsigned> &IP) 199bdd1243dSDimitry Andric : Name(N), TypeParams(TP), IntParams(IP) {} 200bdd1243dSDimitry Andric KeyTy(const TargetExtType *TT) 201bdd1243dSDimitry Andric : Name(TT->getName()), TypeParams(TT->type_params()), 202bdd1243dSDimitry Andric IntParams(TT->int_params()) {} 203bdd1243dSDimitry Andric 204bdd1243dSDimitry Andric bool operator==(const KeyTy &that) const { 205bdd1243dSDimitry Andric return Name == that.Name && TypeParams == that.TypeParams && 206bdd1243dSDimitry Andric IntParams == that.IntParams; 207bdd1243dSDimitry Andric } 208bdd1243dSDimitry Andric bool operator!=(const KeyTy &that) const { return !this->operator==(that); } 209bdd1243dSDimitry Andric }; 210bdd1243dSDimitry Andric 211bdd1243dSDimitry Andric static inline TargetExtType *getEmptyKey() { 212bdd1243dSDimitry Andric return DenseMapInfo<TargetExtType *>::getEmptyKey(); 213bdd1243dSDimitry Andric } 214bdd1243dSDimitry Andric 215bdd1243dSDimitry Andric static inline TargetExtType *getTombstoneKey() { 216bdd1243dSDimitry Andric return DenseMapInfo<TargetExtType *>::getTombstoneKey(); 217bdd1243dSDimitry Andric } 218bdd1243dSDimitry Andric 219bdd1243dSDimitry Andric static unsigned getHashValue(const KeyTy &Key) { 220bdd1243dSDimitry Andric return hash_combine( 221bdd1243dSDimitry Andric Key.Name, 222bdd1243dSDimitry Andric hash_combine_range(Key.TypeParams.begin(), Key.TypeParams.end()), 223bdd1243dSDimitry Andric hash_combine_range(Key.IntParams.begin(), Key.IntParams.end())); 224bdd1243dSDimitry Andric } 225bdd1243dSDimitry Andric 226bdd1243dSDimitry Andric static unsigned getHashValue(const TargetExtType *FT) { 227bdd1243dSDimitry Andric return getHashValue(KeyTy(FT)); 228bdd1243dSDimitry Andric } 229bdd1243dSDimitry Andric 230bdd1243dSDimitry Andric static bool isEqual(const KeyTy &LHS, const TargetExtType *RHS) { 231bdd1243dSDimitry Andric if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 232bdd1243dSDimitry Andric return false; 233bdd1243dSDimitry Andric return LHS == KeyTy(RHS); 234bdd1243dSDimitry Andric } 235bdd1243dSDimitry Andric 236bdd1243dSDimitry Andric static bool isEqual(const TargetExtType *LHS, const TargetExtType *RHS) { 237bdd1243dSDimitry Andric return LHS == RHS; 238bdd1243dSDimitry Andric } 239bdd1243dSDimitry Andric }; 240bdd1243dSDimitry Andric 2410b57cec5SDimitry Andric /// Structure for hashing arbitrary MDNode operands. 2420b57cec5SDimitry Andric class MDNodeOpsKey { 2430b57cec5SDimitry Andric ArrayRef<Metadata *> RawOps; 2440b57cec5SDimitry Andric ArrayRef<MDOperand> Ops; 2450b57cec5SDimitry Andric unsigned Hash; 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric protected: 2480b57cec5SDimitry Andric MDNodeOpsKey(ArrayRef<Metadata *> Ops) 2490b57cec5SDimitry Andric : RawOps(Ops), Hash(calculateHash(Ops)) {} 2500b57cec5SDimitry Andric 2510b57cec5SDimitry Andric template <class NodeTy> 2520b57cec5SDimitry Andric MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0) 2530b57cec5SDimitry Andric : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {} 2540b57cec5SDimitry Andric 2550b57cec5SDimitry Andric template <class NodeTy> 2560b57cec5SDimitry Andric bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const { 2570b57cec5SDimitry Andric if (getHash() != RHS->getHash()) 2580b57cec5SDimitry Andric return false; 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andric assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?"); 2610b57cec5SDimitry Andric return RawOps.empty() ? compareOps(Ops, RHS, Offset) 2620b57cec5SDimitry Andric : compareOps(RawOps, RHS, Offset); 2630b57cec5SDimitry Andric } 2640b57cec5SDimitry Andric 2650b57cec5SDimitry Andric static unsigned calculateHash(MDNode *N, unsigned Offset = 0); 2660b57cec5SDimitry Andric 2670b57cec5SDimitry Andric private: 2680b57cec5SDimitry Andric template <class T> 2690b57cec5SDimitry Andric static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) { 2700b57cec5SDimitry Andric if (Ops.size() != RHS->getNumOperands() - Offset) 2710b57cec5SDimitry Andric return false; 2720b57cec5SDimitry Andric return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset); 2730b57cec5SDimitry Andric } 2740b57cec5SDimitry Andric 2750b57cec5SDimitry Andric static unsigned calculateHash(ArrayRef<Metadata *> Ops); 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andric public: 2780b57cec5SDimitry Andric unsigned getHash() const { return Hash; } 2790b57cec5SDimitry Andric }; 2800b57cec5SDimitry Andric 2810b57cec5SDimitry Andric template <class NodeTy> struct MDNodeKeyImpl; 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andric /// Configuration point for MDNodeInfo::isEqual(). 2840b57cec5SDimitry Andric template <class NodeTy> struct MDNodeSubsetEqualImpl { 2850b57cec5SDimitry Andric using KeyTy = MDNodeKeyImpl<NodeTy>; 2860b57cec5SDimitry Andric 2870b57cec5SDimitry Andric static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) { 2880b57cec5SDimitry Andric return false; 2890b57cec5SDimitry Andric } 2900b57cec5SDimitry Andric 2910b57cec5SDimitry Andric static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) { 2920b57cec5SDimitry Andric return false; 2930b57cec5SDimitry Andric } 2940b57cec5SDimitry Andric }; 2950b57cec5SDimitry Andric 2960b57cec5SDimitry Andric /// DenseMapInfo for MDTuple. 2970b57cec5SDimitry Andric /// 2980b57cec5SDimitry Andric /// Note that we don't need the is-function-local bit, since that's implicit in 2990b57cec5SDimitry Andric /// the operands. 3000b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey { 3010b57cec5SDimitry Andric MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {} 3020b57cec5SDimitry Andric MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {} 3030b57cec5SDimitry Andric 3040b57cec5SDimitry Andric bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); } 3050b57cec5SDimitry Andric 3060b57cec5SDimitry Andric unsigned getHashValue() const { return getHash(); } 3070b57cec5SDimitry Andric 3080b57cec5SDimitry Andric static unsigned calculateHash(MDTuple *N) { 3090b57cec5SDimitry Andric return MDNodeOpsKey::calculateHash(N); 3100b57cec5SDimitry Andric } 3110b57cec5SDimitry Andric }; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andric /// DenseMapInfo for DILocation. 3140b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DILocation> { 3150b57cec5SDimitry Andric unsigned Line; 3160b57cec5SDimitry Andric unsigned Column; 3170b57cec5SDimitry Andric Metadata *Scope; 3180b57cec5SDimitry Andric Metadata *InlinedAt; 3190b57cec5SDimitry Andric bool ImplicitCode; 3200b57cec5SDimitry Andric 3210b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, 3220b57cec5SDimitry Andric Metadata *InlinedAt, bool ImplicitCode) 3230b57cec5SDimitry Andric : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt), 3240b57cec5SDimitry Andric ImplicitCode(ImplicitCode) {} 3250b57cec5SDimitry Andric MDNodeKeyImpl(const DILocation *L) 3260b57cec5SDimitry Andric : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), 3270b57cec5SDimitry Andric InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {} 3280b57cec5SDimitry Andric 3290b57cec5SDimitry Andric bool isKeyOf(const DILocation *RHS) const { 3300b57cec5SDimitry Andric return Line == RHS->getLine() && Column == RHS->getColumn() && 3310b57cec5SDimitry Andric Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() && 3320b57cec5SDimitry Andric ImplicitCode == RHS->isImplicitCode(); 3330b57cec5SDimitry Andric } 3340b57cec5SDimitry Andric 3350b57cec5SDimitry Andric unsigned getHashValue() const { 3360b57cec5SDimitry Andric return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode); 3370b57cec5SDimitry Andric } 3380b57cec5SDimitry Andric }; 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andric /// DenseMapInfo for GenericDINode. 3410b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey { 3420b57cec5SDimitry Andric unsigned Tag; 3430b57cec5SDimitry Andric MDString *Header; 3440b57cec5SDimitry Andric 3450b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps) 3460b57cec5SDimitry Andric : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} 3470b57cec5SDimitry Andric MDNodeKeyImpl(const GenericDINode *N) 3480b57cec5SDimitry Andric : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {} 3490b57cec5SDimitry Andric 3500b57cec5SDimitry Andric bool isKeyOf(const GenericDINode *RHS) const { 3510b57cec5SDimitry Andric return Tag == RHS->getTag() && Header == RHS->getRawHeader() && 3520b57cec5SDimitry Andric compareOps(RHS, 1); 3530b57cec5SDimitry Andric } 3540b57cec5SDimitry Andric 3550b57cec5SDimitry Andric unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); } 3560b57cec5SDimitry Andric 3570b57cec5SDimitry Andric static unsigned calculateHash(GenericDINode *N) { 3580b57cec5SDimitry Andric return MDNodeOpsKey::calculateHash(N, 1); 3590b57cec5SDimitry Andric } 3600b57cec5SDimitry Andric }; 3610b57cec5SDimitry Andric 3620b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DISubrange> { 3630b57cec5SDimitry Andric Metadata *CountNode; 3645ffd83dbSDimitry Andric Metadata *LowerBound; 3655ffd83dbSDimitry Andric Metadata *UpperBound; 3665ffd83dbSDimitry Andric Metadata *Stride; 3670b57cec5SDimitry Andric 3685ffd83dbSDimitry Andric MDNodeKeyImpl(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, 3695ffd83dbSDimitry Andric Metadata *Stride) 3705ffd83dbSDimitry Andric : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound), 3715ffd83dbSDimitry Andric Stride(Stride) {} 3720b57cec5SDimitry Andric MDNodeKeyImpl(const DISubrange *N) 3735ffd83dbSDimitry Andric : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()), 3745ffd83dbSDimitry Andric UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {} 3750b57cec5SDimitry Andric 3760b57cec5SDimitry Andric bool isKeyOf(const DISubrange *RHS) const { 3775ffd83dbSDimitry Andric auto BoundsEqual = [=](Metadata *Node1, Metadata *Node2) -> bool { 3785ffd83dbSDimitry Andric if (Node1 == Node2) 3790b57cec5SDimitry Andric return true; 3800b57cec5SDimitry Andric 3815ffd83dbSDimitry Andric ConstantAsMetadata *MD1 = dyn_cast_or_null<ConstantAsMetadata>(Node1); 3825ffd83dbSDimitry Andric ConstantAsMetadata *MD2 = dyn_cast_or_null<ConstantAsMetadata>(Node2); 3835ffd83dbSDimitry Andric if (MD1 && MD2) { 3845ffd83dbSDimitry Andric ConstantInt *CV1 = cast<ConstantInt>(MD1->getValue()); 3855ffd83dbSDimitry Andric ConstantInt *CV2 = cast<ConstantInt>(MD2->getValue()); 3865ffd83dbSDimitry Andric if (CV1->getSExtValue() == CV2->getSExtValue()) 3875ffd83dbSDimitry Andric return true; 3885ffd83dbSDimitry Andric } 3895ffd83dbSDimitry Andric return false; 3905ffd83dbSDimitry Andric }; 3915ffd83dbSDimitry Andric 3925ffd83dbSDimitry Andric return BoundsEqual(CountNode, RHS->getRawCountNode()) && 3935ffd83dbSDimitry Andric BoundsEqual(LowerBound, RHS->getRawLowerBound()) && 3945ffd83dbSDimitry Andric BoundsEqual(UpperBound, RHS->getRawUpperBound()) && 3955ffd83dbSDimitry Andric BoundsEqual(Stride, RHS->getRawStride()); 3960b57cec5SDimitry Andric } 3970b57cec5SDimitry Andric 3980b57cec5SDimitry Andric unsigned getHashValue() const { 3995ffd83dbSDimitry Andric if (CountNode) 4000b57cec5SDimitry Andric if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode)) 4010b57cec5SDimitry Andric return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(), 4025ffd83dbSDimitry Andric LowerBound, UpperBound, Stride); 4035ffd83dbSDimitry Andric return hash_combine(CountNode, LowerBound, UpperBound, Stride); 4040b57cec5SDimitry Andric } 4050b57cec5SDimitry Andric }; 4060b57cec5SDimitry Andric 407e8d8bef9SDimitry Andric template <> struct MDNodeKeyImpl<DIGenericSubrange> { 408e8d8bef9SDimitry Andric Metadata *CountNode; 409e8d8bef9SDimitry Andric Metadata *LowerBound; 410e8d8bef9SDimitry Andric Metadata *UpperBound; 411e8d8bef9SDimitry Andric Metadata *Stride; 412e8d8bef9SDimitry Andric 413e8d8bef9SDimitry Andric MDNodeKeyImpl(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound, 414e8d8bef9SDimitry Andric Metadata *Stride) 415e8d8bef9SDimitry Andric : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound), 416e8d8bef9SDimitry Andric Stride(Stride) {} 417e8d8bef9SDimitry Andric MDNodeKeyImpl(const DIGenericSubrange *N) 418e8d8bef9SDimitry Andric : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()), 419e8d8bef9SDimitry Andric UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {} 420e8d8bef9SDimitry Andric 421e8d8bef9SDimitry Andric bool isKeyOf(const DIGenericSubrange *RHS) const { 422e8d8bef9SDimitry Andric return (CountNode == RHS->getRawCountNode()) && 423e8d8bef9SDimitry Andric (LowerBound == RHS->getRawLowerBound()) && 424e8d8bef9SDimitry Andric (UpperBound == RHS->getRawUpperBound()) && 425e8d8bef9SDimitry Andric (Stride == RHS->getRawStride()); 426e8d8bef9SDimitry Andric } 427e8d8bef9SDimitry Andric 428e8d8bef9SDimitry Andric unsigned getHashValue() const { 429e8d8bef9SDimitry Andric auto *MD = dyn_cast_or_null<ConstantAsMetadata>(CountNode); 430e8d8bef9SDimitry Andric if (CountNode && MD) 431e8d8bef9SDimitry Andric return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(), 432e8d8bef9SDimitry Andric LowerBound, UpperBound, Stride); 433e8d8bef9SDimitry Andric return hash_combine(CountNode, LowerBound, UpperBound, Stride); 434e8d8bef9SDimitry Andric } 435e8d8bef9SDimitry Andric }; 436e8d8bef9SDimitry Andric 4370b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIEnumerator> { 4385ffd83dbSDimitry Andric APInt Value; 4390b57cec5SDimitry Andric MDString *Name; 4400b57cec5SDimitry Andric bool IsUnsigned; 4410b57cec5SDimitry Andric 4425ffd83dbSDimitry Andric MDNodeKeyImpl(APInt Value, bool IsUnsigned, MDString *Name) 4430b57cec5SDimitry Andric : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {} 4445ffd83dbSDimitry Andric MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name) 4455ffd83dbSDimitry Andric : Value(APInt(64, Value, !IsUnsigned)), Name(Name), 4465ffd83dbSDimitry Andric IsUnsigned(IsUnsigned) {} 4470b57cec5SDimitry Andric MDNodeKeyImpl(const DIEnumerator *N) 4480b57cec5SDimitry Andric : Value(N->getValue()), Name(N->getRawName()), 4490b57cec5SDimitry Andric IsUnsigned(N->isUnsigned()) {} 4500b57cec5SDimitry Andric 4510b57cec5SDimitry Andric bool isKeyOf(const DIEnumerator *RHS) const { 4520eae32dcSDimitry Andric return Value.getBitWidth() == RHS->getValue().getBitWidth() && 4530eae32dcSDimitry Andric Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() && 4540eae32dcSDimitry Andric Name == RHS->getRawName(); 4550b57cec5SDimitry Andric } 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andric unsigned getHashValue() const { return hash_combine(Value, Name); } 4580b57cec5SDimitry Andric }; 4590b57cec5SDimitry Andric 4600b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIBasicType> { 4610b57cec5SDimitry Andric unsigned Tag; 4620b57cec5SDimitry Andric MDString *Name; 4630b57cec5SDimitry Andric uint64_t SizeInBits; 4640b57cec5SDimitry Andric uint32_t AlignInBits; 4650b57cec5SDimitry Andric unsigned Encoding; 4660b57cec5SDimitry Andric unsigned Flags; 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits, 4690b57cec5SDimitry Andric uint32_t AlignInBits, unsigned Encoding, unsigned Flags) 4700b57cec5SDimitry Andric : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits), 4710b57cec5SDimitry Andric Encoding(Encoding), Flags(Flags) {} 4720b57cec5SDimitry Andric MDNodeKeyImpl(const DIBasicType *N) 4730b57cec5SDimitry Andric : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()), 474349cc55cSDimitry Andric AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), 475349cc55cSDimitry Andric Flags(N->getFlags()) {} 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric bool isKeyOf(const DIBasicType *RHS) const { 4780b57cec5SDimitry Andric return Tag == RHS->getTag() && Name == RHS->getRawName() && 4790b57cec5SDimitry Andric SizeInBits == RHS->getSizeInBits() && 4800b57cec5SDimitry Andric AlignInBits == RHS->getAlignInBits() && 481349cc55cSDimitry Andric Encoding == RHS->getEncoding() && Flags == RHS->getFlags(); 4820b57cec5SDimitry Andric } 4830b57cec5SDimitry Andric 4840b57cec5SDimitry Andric unsigned getHashValue() const { 4850b57cec5SDimitry Andric return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding); 4860b57cec5SDimitry Andric } 4870b57cec5SDimitry Andric }; 4880b57cec5SDimitry Andric 489e8d8bef9SDimitry Andric template <> struct MDNodeKeyImpl<DIStringType> { 490e8d8bef9SDimitry Andric unsigned Tag; 491e8d8bef9SDimitry Andric MDString *Name; 492e8d8bef9SDimitry Andric Metadata *StringLength; 493e8d8bef9SDimitry Andric Metadata *StringLengthExp; 49404eeddc0SDimitry Andric Metadata *StringLocationExp; 495e8d8bef9SDimitry Andric uint64_t SizeInBits; 496e8d8bef9SDimitry Andric uint32_t AlignInBits; 497e8d8bef9SDimitry Andric unsigned Encoding; 498e8d8bef9SDimitry Andric 499e8d8bef9SDimitry Andric MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *StringLength, 50004eeddc0SDimitry Andric Metadata *StringLengthExp, Metadata *StringLocationExp, 50104eeddc0SDimitry Andric uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding) 502e8d8bef9SDimitry Andric : Tag(Tag), Name(Name), StringLength(StringLength), 50304eeddc0SDimitry Andric StringLengthExp(StringLengthExp), StringLocationExp(StringLocationExp), 50404eeddc0SDimitry Andric SizeInBits(SizeInBits), AlignInBits(AlignInBits), Encoding(Encoding) {} 505e8d8bef9SDimitry Andric MDNodeKeyImpl(const DIStringType *N) 506e8d8bef9SDimitry Andric : Tag(N->getTag()), Name(N->getRawName()), 507e8d8bef9SDimitry Andric StringLength(N->getRawStringLength()), 508e8d8bef9SDimitry Andric StringLengthExp(N->getRawStringLengthExp()), 50904eeddc0SDimitry Andric StringLocationExp(N->getRawStringLocationExp()), 510e8d8bef9SDimitry Andric SizeInBits(N->getSizeInBits()), AlignInBits(N->getAlignInBits()), 511e8d8bef9SDimitry Andric Encoding(N->getEncoding()) {} 512e8d8bef9SDimitry Andric 513e8d8bef9SDimitry Andric bool isKeyOf(const DIStringType *RHS) const { 514e8d8bef9SDimitry Andric return Tag == RHS->getTag() && Name == RHS->getRawName() && 51506c3fb27SDimitry Andric StringLength == RHS->getRawStringLength() && 51606c3fb27SDimitry Andric StringLengthExp == RHS->getRawStringLengthExp() && 51706c3fb27SDimitry Andric StringLocationExp == RHS->getRawStringLocationExp() && 518e8d8bef9SDimitry Andric SizeInBits == RHS->getSizeInBits() && 519e8d8bef9SDimitry Andric AlignInBits == RHS->getAlignInBits() && 520e8d8bef9SDimitry Andric Encoding == RHS->getEncoding(); 521e8d8bef9SDimitry Andric } 52206c3fb27SDimitry Andric unsigned getHashValue() const { 52306c3fb27SDimitry Andric // Intentionally computes the hash on a subset of the operands for 52406c3fb27SDimitry Andric // performance reason. The subset has to be significant enough to avoid 52506c3fb27SDimitry Andric // collision "most of the time". There is no correctness issue in case of 52606c3fb27SDimitry Andric // collision because of the full check above. 52706c3fb27SDimitry Andric return hash_combine(Tag, Name, StringLength, Encoding); 52806c3fb27SDimitry Andric } 529e8d8bef9SDimitry Andric }; 530e8d8bef9SDimitry Andric 5310b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIDerivedType> { 5320b57cec5SDimitry Andric unsigned Tag; 5330b57cec5SDimitry Andric MDString *Name; 5340b57cec5SDimitry Andric Metadata *File; 5350b57cec5SDimitry Andric unsigned Line; 5360b57cec5SDimitry Andric Metadata *Scope; 5370b57cec5SDimitry Andric Metadata *BaseType; 5380b57cec5SDimitry Andric uint64_t SizeInBits; 5390b57cec5SDimitry Andric uint64_t OffsetInBits; 5400b57cec5SDimitry Andric uint32_t AlignInBits; 541bdd1243dSDimitry Andric std::optional<unsigned> DWARFAddressSpace; 5420b57cec5SDimitry Andric unsigned Flags; 5430b57cec5SDimitry Andric Metadata *ExtraData; 544349cc55cSDimitry Andric Metadata *Annotations; 5450b57cec5SDimitry Andric 5460b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, 5470b57cec5SDimitry Andric Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, 5480b57cec5SDimitry Andric uint32_t AlignInBits, uint64_t OffsetInBits, 549bdd1243dSDimitry Andric std::optional<unsigned> DWARFAddressSpace, unsigned Flags, 550349cc55cSDimitry Andric Metadata *ExtraData, Metadata *Annotations) 5510b57cec5SDimitry Andric : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), 5520b57cec5SDimitry Andric BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), 5530b57cec5SDimitry Andric AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace), 554349cc55cSDimitry Andric Flags(Flags), ExtraData(ExtraData), Annotations(Annotations) {} 5550b57cec5SDimitry Andric MDNodeKeyImpl(const DIDerivedType *N) 5560b57cec5SDimitry Andric : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), 5570b57cec5SDimitry Andric Line(N->getLine()), Scope(N->getRawScope()), 5580b57cec5SDimitry Andric BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), 5590b57cec5SDimitry Andric OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()), 5600b57cec5SDimitry Andric DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()), 561349cc55cSDimitry Andric ExtraData(N->getRawExtraData()), Annotations(N->getRawAnnotations()) {} 5620b57cec5SDimitry Andric 5630b57cec5SDimitry Andric bool isKeyOf(const DIDerivedType *RHS) const { 5640b57cec5SDimitry Andric return Tag == RHS->getTag() && Name == RHS->getRawName() && 5650b57cec5SDimitry Andric File == RHS->getRawFile() && Line == RHS->getLine() && 5660b57cec5SDimitry Andric Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && 5670b57cec5SDimitry Andric SizeInBits == RHS->getSizeInBits() && 5680b57cec5SDimitry Andric AlignInBits == RHS->getAlignInBits() && 5690b57cec5SDimitry Andric OffsetInBits == RHS->getOffsetInBits() && 5700b57cec5SDimitry Andric DWARFAddressSpace == RHS->getDWARFAddressSpace() && 571349cc55cSDimitry Andric Flags == RHS->getFlags() && ExtraData == RHS->getRawExtraData() && 572349cc55cSDimitry Andric Annotations == RHS->getRawAnnotations(); 5730b57cec5SDimitry Andric } 5740b57cec5SDimitry Andric 5750b57cec5SDimitry Andric unsigned getHashValue() const { 5760b57cec5SDimitry Andric // If this is a member inside an ODR type, only hash the type and the name. 5770b57cec5SDimitry Andric // Otherwise the hash will be stronger than 5780b57cec5SDimitry Andric // MDNodeSubsetEqualImpl::isODRMember(). 5790b57cec5SDimitry Andric if (Tag == dwarf::DW_TAG_member && Name) 5800b57cec5SDimitry Andric if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope)) 5810b57cec5SDimitry Andric if (CT->getRawIdentifier()) 5820b57cec5SDimitry Andric return hash_combine(Name, Scope); 5830b57cec5SDimitry Andric 5840b57cec5SDimitry Andric // Intentionally computes the hash on a subset of the operands for 5850b57cec5SDimitry Andric // performance reason. The subset has to be significant enough to avoid 5860b57cec5SDimitry Andric // collision "most of the time". There is no correctness issue in case of 5870b57cec5SDimitry Andric // collision because of the full check above. 5880b57cec5SDimitry Andric return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags); 5890b57cec5SDimitry Andric } 5900b57cec5SDimitry Andric }; 5910b57cec5SDimitry Andric 5920b57cec5SDimitry Andric template <> struct MDNodeSubsetEqualImpl<DIDerivedType> { 5930b57cec5SDimitry Andric using KeyTy = MDNodeKeyImpl<DIDerivedType>; 5940b57cec5SDimitry Andric 5950b57cec5SDimitry Andric static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) { 5960b57cec5SDimitry Andric return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS); 5970b57cec5SDimitry Andric } 5980b57cec5SDimitry Andric 599349cc55cSDimitry Andric static bool isSubsetEqual(const DIDerivedType *LHS, 600349cc55cSDimitry Andric const DIDerivedType *RHS) { 6010b57cec5SDimitry Andric return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(), 6020b57cec5SDimitry Andric RHS); 6030b57cec5SDimitry Andric } 6040b57cec5SDimitry Andric 6050b57cec5SDimitry Andric /// Subprograms compare equal if they declare the same function in an ODR 6060b57cec5SDimitry Andric /// type. 6070b57cec5SDimitry Andric static bool isODRMember(unsigned Tag, const Metadata *Scope, 6080b57cec5SDimitry Andric const MDString *Name, const DIDerivedType *RHS) { 6090b57cec5SDimitry Andric // Check whether the LHS is eligible. 6100b57cec5SDimitry Andric if (Tag != dwarf::DW_TAG_member || !Name) 6110b57cec5SDimitry Andric return false; 6120b57cec5SDimitry Andric 6130b57cec5SDimitry Andric auto *CT = dyn_cast_or_null<DICompositeType>(Scope); 6140b57cec5SDimitry Andric if (!CT || !CT->getRawIdentifier()) 6150b57cec5SDimitry Andric return false; 6160b57cec5SDimitry Andric 6170b57cec5SDimitry Andric // Compare to the RHS. 6180b57cec5SDimitry Andric return Tag == RHS->getTag() && Name == RHS->getRawName() && 6190b57cec5SDimitry Andric Scope == RHS->getRawScope(); 6200b57cec5SDimitry Andric } 6210b57cec5SDimitry Andric }; 6220b57cec5SDimitry Andric 6230b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DICompositeType> { 6240b57cec5SDimitry Andric unsigned Tag; 6250b57cec5SDimitry Andric MDString *Name; 6260b57cec5SDimitry Andric Metadata *File; 6270b57cec5SDimitry Andric unsigned Line; 6280b57cec5SDimitry Andric Metadata *Scope; 6290b57cec5SDimitry Andric Metadata *BaseType; 6300b57cec5SDimitry Andric uint64_t SizeInBits; 6310b57cec5SDimitry Andric uint64_t OffsetInBits; 6320b57cec5SDimitry Andric uint32_t AlignInBits; 6330b57cec5SDimitry Andric unsigned Flags; 6340b57cec5SDimitry Andric Metadata *Elements; 6350b57cec5SDimitry Andric unsigned RuntimeLang; 6360b57cec5SDimitry Andric Metadata *VTableHolder; 6370b57cec5SDimitry Andric Metadata *TemplateParams; 6380b57cec5SDimitry Andric MDString *Identifier; 6390b57cec5SDimitry Andric Metadata *Discriminator; 6405ffd83dbSDimitry Andric Metadata *DataLocation; 641e8d8bef9SDimitry Andric Metadata *Associated; 642e8d8bef9SDimitry Andric Metadata *Allocated; 643e8d8bef9SDimitry Andric Metadata *Rank; 644349cc55cSDimitry Andric Metadata *Annotations; 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, 6470b57cec5SDimitry Andric Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, 6480b57cec5SDimitry Andric uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, 6490b57cec5SDimitry Andric Metadata *Elements, unsigned RuntimeLang, 6500b57cec5SDimitry Andric Metadata *VTableHolder, Metadata *TemplateParams, 6515ffd83dbSDimitry Andric MDString *Identifier, Metadata *Discriminator, 652e8d8bef9SDimitry Andric Metadata *DataLocation, Metadata *Associated, 653349cc55cSDimitry Andric Metadata *Allocated, Metadata *Rank, Metadata *Annotations) 6540b57cec5SDimitry Andric : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), 6550b57cec5SDimitry Andric BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), 6560b57cec5SDimitry Andric AlignInBits(AlignInBits), Flags(Flags), Elements(Elements), 6570b57cec5SDimitry Andric RuntimeLang(RuntimeLang), VTableHolder(VTableHolder), 6580b57cec5SDimitry Andric TemplateParams(TemplateParams), Identifier(Identifier), 659e8d8bef9SDimitry Andric Discriminator(Discriminator), DataLocation(DataLocation), 660349cc55cSDimitry Andric Associated(Associated), Allocated(Allocated), Rank(Rank), 661349cc55cSDimitry Andric Annotations(Annotations) {} 6620b57cec5SDimitry Andric MDNodeKeyImpl(const DICompositeType *N) 6630b57cec5SDimitry Andric : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), 6640b57cec5SDimitry Andric Line(N->getLine()), Scope(N->getRawScope()), 6650b57cec5SDimitry Andric BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), 6660b57cec5SDimitry Andric OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()), 6670b57cec5SDimitry Andric Flags(N->getFlags()), Elements(N->getRawElements()), 6680b57cec5SDimitry Andric RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()), 6690b57cec5SDimitry Andric TemplateParams(N->getRawTemplateParams()), 6700b57cec5SDimitry Andric Identifier(N->getRawIdentifier()), 6715ffd83dbSDimitry Andric Discriminator(N->getRawDiscriminator()), 672e8d8bef9SDimitry Andric DataLocation(N->getRawDataLocation()), 673e8d8bef9SDimitry Andric Associated(N->getRawAssociated()), Allocated(N->getRawAllocated()), 674349cc55cSDimitry Andric Rank(N->getRawRank()), Annotations(N->getRawAnnotations()) {} 6750b57cec5SDimitry Andric 6760b57cec5SDimitry Andric bool isKeyOf(const DICompositeType *RHS) const { 6770b57cec5SDimitry Andric return Tag == RHS->getTag() && Name == RHS->getRawName() && 6780b57cec5SDimitry Andric File == RHS->getRawFile() && Line == RHS->getLine() && 6790b57cec5SDimitry Andric Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && 6800b57cec5SDimitry Andric SizeInBits == RHS->getSizeInBits() && 6810b57cec5SDimitry Andric AlignInBits == RHS->getAlignInBits() && 6820b57cec5SDimitry Andric OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() && 6830b57cec5SDimitry Andric Elements == RHS->getRawElements() && 6840b57cec5SDimitry Andric RuntimeLang == RHS->getRuntimeLang() && 6850b57cec5SDimitry Andric VTableHolder == RHS->getRawVTableHolder() && 6860b57cec5SDimitry Andric TemplateParams == RHS->getRawTemplateParams() && 6870b57cec5SDimitry Andric Identifier == RHS->getRawIdentifier() && 6885ffd83dbSDimitry Andric Discriminator == RHS->getRawDiscriminator() && 689e8d8bef9SDimitry Andric DataLocation == RHS->getRawDataLocation() && 690e8d8bef9SDimitry Andric Associated == RHS->getRawAssociated() && 691349cc55cSDimitry Andric Allocated == RHS->getRawAllocated() && Rank == RHS->getRawRank() && 692349cc55cSDimitry Andric Annotations == RHS->getRawAnnotations(); 6930b57cec5SDimitry Andric } 6940b57cec5SDimitry Andric 6950b57cec5SDimitry Andric unsigned getHashValue() const { 6960b57cec5SDimitry Andric // Intentionally computes the hash on a subset of the operands for 6970b57cec5SDimitry Andric // performance reason. The subset has to be significant enough to avoid 6980b57cec5SDimitry Andric // collision "most of the time". There is no correctness issue in case of 6990b57cec5SDimitry Andric // collision because of the full check above. 7000b57cec5SDimitry Andric return hash_combine(Name, File, Line, BaseType, Scope, Elements, 701349cc55cSDimitry Andric TemplateParams, Annotations); 7020b57cec5SDimitry Andric } 7030b57cec5SDimitry Andric }; 7040b57cec5SDimitry Andric 7050b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DISubroutineType> { 7060b57cec5SDimitry Andric unsigned Flags; 7070b57cec5SDimitry Andric uint8_t CC; 7080b57cec5SDimitry Andric Metadata *TypeArray; 7090b57cec5SDimitry Andric 7100b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray) 7110b57cec5SDimitry Andric : Flags(Flags), CC(CC), TypeArray(TypeArray) {} 7120b57cec5SDimitry Andric MDNodeKeyImpl(const DISubroutineType *N) 7130b57cec5SDimitry Andric : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {} 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andric bool isKeyOf(const DISubroutineType *RHS) const { 7160b57cec5SDimitry Andric return Flags == RHS->getFlags() && CC == RHS->getCC() && 7170b57cec5SDimitry Andric TypeArray == RHS->getRawTypeArray(); 7180b57cec5SDimitry Andric } 7190b57cec5SDimitry Andric 7200b57cec5SDimitry Andric unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); } 7210b57cec5SDimitry Andric }; 7220b57cec5SDimitry Andric 7230b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIFile> { 7240b57cec5SDimitry Andric MDString *Filename; 7250b57cec5SDimitry Andric MDString *Directory; 726bdd1243dSDimitry Andric std::optional<DIFile::ChecksumInfo<MDString *>> Checksum; 727bdd1243dSDimitry Andric MDString *Source; 7280b57cec5SDimitry Andric 7290b57cec5SDimitry Andric MDNodeKeyImpl(MDString *Filename, MDString *Directory, 730bdd1243dSDimitry Andric std::optional<DIFile::ChecksumInfo<MDString *>> Checksum, 731bdd1243dSDimitry Andric MDString *Source) 7320b57cec5SDimitry Andric : Filename(Filename), Directory(Directory), Checksum(Checksum), 7330b57cec5SDimitry Andric Source(Source) {} 7340b57cec5SDimitry Andric MDNodeKeyImpl(const DIFile *N) 7350b57cec5SDimitry Andric : Filename(N->getRawFilename()), Directory(N->getRawDirectory()), 7360b57cec5SDimitry Andric Checksum(N->getRawChecksum()), Source(N->getRawSource()) {} 7370b57cec5SDimitry Andric 7380b57cec5SDimitry Andric bool isKeyOf(const DIFile *RHS) const { 7390b57cec5SDimitry Andric return Filename == RHS->getRawFilename() && 7400b57cec5SDimitry Andric Directory == RHS->getRawDirectory() && 741349cc55cSDimitry Andric Checksum == RHS->getRawChecksum() && Source == RHS->getRawSource(); 7420b57cec5SDimitry Andric } 7430b57cec5SDimitry Andric 7440b57cec5SDimitry Andric unsigned getHashValue() const { 745349cc55cSDimitry Andric return hash_combine(Filename, Directory, Checksum ? Checksum->Kind : 0, 746bdd1243dSDimitry Andric Checksum ? Checksum->Value : nullptr, Source); 7470b57cec5SDimitry Andric } 7480b57cec5SDimitry Andric }; 7490b57cec5SDimitry Andric 7500b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DISubprogram> { 7510b57cec5SDimitry Andric Metadata *Scope; 7520b57cec5SDimitry Andric MDString *Name; 7530b57cec5SDimitry Andric MDString *LinkageName; 7540b57cec5SDimitry Andric Metadata *File; 7550b57cec5SDimitry Andric unsigned Line; 7560b57cec5SDimitry Andric Metadata *Type; 7570b57cec5SDimitry Andric unsigned ScopeLine; 7580b57cec5SDimitry Andric Metadata *ContainingType; 7590b57cec5SDimitry Andric unsigned VirtualIndex; 7600b57cec5SDimitry Andric int ThisAdjustment; 7610b57cec5SDimitry Andric unsigned Flags; 7620b57cec5SDimitry Andric unsigned SPFlags; 7630b57cec5SDimitry Andric Metadata *Unit; 7640b57cec5SDimitry Andric Metadata *TemplateParams; 7650b57cec5SDimitry Andric Metadata *Declaration; 7660b57cec5SDimitry Andric Metadata *RetainedNodes; 7670b57cec5SDimitry Andric Metadata *ThrownTypes; 768349cc55cSDimitry Andric Metadata *Annotations; 76981ad6265SDimitry Andric MDString *TargetFuncName; 7700b57cec5SDimitry Andric 7710b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, 7720b57cec5SDimitry Andric Metadata *File, unsigned Line, Metadata *Type, 7730b57cec5SDimitry Andric unsigned ScopeLine, Metadata *ContainingType, 7740b57cec5SDimitry Andric unsigned VirtualIndex, int ThisAdjustment, unsigned Flags, 7750b57cec5SDimitry Andric unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams, 7760b57cec5SDimitry Andric Metadata *Declaration, Metadata *RetainedNodes, 77781ad6265SDimitry Andric Metadata *ThrownTypes, Metadata *Annotations, 77881ad6265SDimitry Andric MDString *TargetFuncName) 7790b57cec5SDimitry Andric : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), 7800b57cec5SDimitry Andric Line(Line), Type(Type), ScopeLine(ScopeLine), 7810b57cec5SDimitry Andric ContainingType(ContainingType), VirtualIndex(VirtualIndex), 7820b57cec5SDimitry Andric ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags), 7830b57cec5SDimitry Andric Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration), 784349cc55cSDimitry Andric RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes), 78581ad6265SDimitry Andric Annotations(Annotations), TargetFuncName(TargetFuncName) {} 7860b57cec5SDimitry Andric MDNodeKeyImpl(const DISubprogram *N) 7870b57cec5SDimitry Andric : Scope(N->getRawScope()), Name(N->getRawName()), 7880b57cec5SDimitry Andric LinkageName(N->getRawLinkageName()), File(N->getRawFile()), 7890b57cec5SDimitry Andric Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()), 7900b57cec5SDimitry Andric ContainingType(N->getRawContainingType()), 7910b57cec5SDimitry Andric VirtualIndex(N->getVirtualIndex()), 7920b57cec5SDimitry Andric ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()), 7930b57cec5SDimitry Andric SPFlags(N->getSPFlags()), Unit(N->getRawUnit()), 7940b57cec5SDimitry Andric TemplateParams(N->getRawTemplateParams()), 7950b57cec5SDimitry Andric Declaration(N->getRawDeclaration()), 7960b57cec5SDimitry Andric RetainedNodes(N->getRawRetainedNodes()), 797349cc55cSDimitry Andric ThrownTypes(N->getRawThrownTypes()), 79881ad6265SDimitry Andric Annotations(N->getRawAnnotations()), 79981ad6265SDimitry Andric TargetFuncName(N->getRawTargetFuncName()) {} 8000b57cec5SDimitry Andric 8010b57cec5SDimitry Andric bool isKeyOf(const DISubprogram *RHS) const { 8020b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 8030b57cec5SDimitry Andric LinkageName == RHS->getRawLinkageName() && 8040b57cec5SDimitry Andric File == RHS->getRawFile() && Line == RHS->getLine() && 8050b57cec5SDimitry Andric Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() && 8060b57cec5SDimitry Andric ContainingType == RHS->getRawContainingType() && 8070b57cec5SDimitry Andric VirtualIndex == RHS->getVirtualIndex() && 8080b57cec5SDimitry Andric ThisAdjustment == RHS->getThisAdjustment() && 8090b57cec5SDimitry Andric Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() && 8100b57cec5SDimitry Andric Unit == RHS->getUnit() && 8110b57cec5SDimitry Andric TemplateParams == RHS->getRawTemplateParams() && 8120b57cec5SDimitry Andric Declaration == RHS->getRawDeclaration() && 8130b57cec5SDimitry Andric RetainedNodes == RHS->getRawRetainedNodes() && 814349cc55cSDimitry Andric ThrownTypes == RHS->getRawThrownTypes() && 81581ad6265SDimitry Andric Annotations == RHS->getRawAnnotations() && 81681ad6265SDimitry Andric TargetFuncName == RHS->getRawTargetFuncName(); 8170b57cec5SDimitry Andric } 8180b57cec5SDimitry Andric 8190b57cec5SDimitry Andric bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; } 8200b57cec5SDimitry Andric 8210b57cec5SDimitry Andric unsigned getHashValue() const { 8220b57cec5SDimitry Andric // If this is a declaration inside an ODR type, only hash the type and the 8230b57cec5SDimitry Andric // name. Otherwise the hash will be stronger than 8240b57cec5SDimitry Andric // MDNodeSubsetEqualImpl::isDeclarationOfODRMember(). 8250b57cec5SDimitry Andric if (!isDefinition() && LinkageName) 8260b57cec5SDimitry Andric if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope)) 8270b57cec5SDimitry Andric if (CT->getRawIdentifier()) 8280b57cec5SDimitry Andric return hash_combine(LinkageName, Scope); 8290b57cec5SDimitry Andric 8300b57cec5SDimitry Andric // Intentionally computes the hash on a subset of the operands for 8310b57cec5SDimitry Andric // performance reason. The subset has to be significant enough to avoid 8320b57cec5SDimitry Andric // collision "most of the time". There is no correctness issue in case of 8330b57cec5SDimitry Andric // collision because of the full check above. 8340b57cec5SDimitry Andric return hash_combine(Name, Scope, File, Type, Line); 8350b57cec5SDimitry Andric } 8360b57cec5SDimitry Andric }; 8370b57cec5SDimitry Andric 8380b57cec5SDimitry Andric template <> struct MDNodeSubsetEqualImpl<DISubprogram> { 8390b57cec5SDimitry Andric using KeyTy = MDNodeKeyImpl<DISubprogram>; 8400b57cec5SDimitry Andric 8410b57cec5SDimitry Andric static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) { 8420b57cec5SDimitry Andric return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope, 8430b57cec5SDimitry Andric LHS.LinkageName, LHS.TemplateParams, RHS); 8440b57cec5SDimitry Andric } 8450b57cec5SDimitry Andric 8460b57cec5SDimitry Andric static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) { 8470b57cec5SDimitry Andric return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(), 8480b57cec5SDimitry Andric LHS->getRawLinkageName(), 8490b57cec5SDimitry Andric LHS->getRawTemplateParams(), RHS); 8500b57cec5SDimitry Andric } 8510b57cec5SDimitry Andric 8520b57cec5SDimitry Andric /// Subprograms compare equal if they declare the same function in an ODR 8530b57cec5SDimitry Andric /// type. 8540b57cec5SDimitry Andric static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope, 8550b57cec5SDimitry Andric const MDString *LinkageName, 8560b57cec5SDimitry Andric const Metadata *TemplateParams, 8570b57cec5SDimitry Andric const DISubprogram *RHS) { 8580b57cec5SDimitry Andric // Check whether the LHS is eligible. 8590b57cec5SDimitry Andric if (IsDefinition || !Scope || !LinkageName) 8600b57cec5SDimitry Andric return false; 8610b57cec5SDimitry Andric 8620b57cec5SDimitry Andric auto *CT = dyn_cast_or_null<DICompositeType>(Scope); 8630b57cec5SDimitry Andric if (!CT || !CT->getRawIdentifier()) 8640b57cec5SDimitry Andric return false; 8650b57cec5SDimitry Andric 8660b57cec5SDimitry Andric // Compare to the RHS. 8670b57cec5SDimitry Andric // FIXME: We need to compare template parameters here to avoid incorrect 868fe6060f1SDimitry Andric // collisions in mapMetadata when RF_ReuseAndMutateDistinctMDs and a 869fe6060f1SDimitry Andric // ODR-DISubprogram has a non-ODR template parameter (i.e., a 870fe6060f1SDimitry Andric // DICompositeType that does not have an identifier). Eventually we should 871fe6060f1SDimitry Andric // decouple ODR logic from uniquing logic. 8720b57cec5SDimitry Andric return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() && 8730b57cec5SDimitry Andric LinkageName == RHS->getRawLinkageName() && 8740b57cec5SDimitry Andric TemplateParams == RHS->getRawTemplateParams(); 8750b57cec5SDimitry Andric } 8760b57cec5SDimitry Andric }; 8770b57cec5SDimitry Andric 8780b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DILexicalBlock> { 8790b57cec5SDimitry Andric Metadata *Scope; 8800b57cec5SDimitry Andric Metadata *File; 8810b57cec5SDimitry Andric unsigned Line; 8820b57cec5SDimitry Andric unsigned Column; 8830b57cec5SDimitry Andric 8840b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column) 8850b57cec5SDimitry Andric : Scope(Scope), File(File), Line(Line), Column(Column) {} 8860b57cec5SDimitry Andric MDNodeKeyImpl(const DILexicalBlock *N) 8870b57cec5SDimitry Andric : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()), 8880b57cec5SDimitry Andric Column(N->getColumn()) {} 8890b57cec5SDimitry Andric 8900b57cec5SDimitry Andric bool isKeyOf(const DILexicalBlock *RHS) const { 8910b57cec5SDimitry Andric return Scope == RHS->getRawScope() && File == RHS->getRawFile() && 8920b57cec5SDimitry Andric Line == RHS->getLine() && Column == RHS->getColumn(); 8930b57cec5SDimitry Andric } 8940b57cec5SDimitry Andric 8950b57cec5SDimitry Andric unsigned getHashValue() const { 8960b57cec5SDimitry Andric return hash_combine(Scope, File, Line, Column); 8970b57cec5SDimitry Andric } 8980b57cec5SDimitry Andric }; 8990b57cec5SDimitry Andric 9000b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DILexicalBlockFile> { 9010b57cec5SDimitry Andric Metadata *Scope; 9020b57cec5SDimitry Andric Metadata *File; 9030b57cec5SDimitry Andric unsigned Discriminator; 9040b57cec5SDimitry Andric 9050b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator) 9060b57cec5SDimitry Andric : Scope(Scope), File(File), Discriminator(Discriminator) {} 9070b57cec5SDimitry Andric MDNodeKeyImpl(const DILexicalBlockFile *N) 9080b57cec5SDimitry Andric : Scope(N->getRawScope()), File(N->getRawFile()), 9090b57cec5SDimitry Andric Discriminator(N->getDiscriminator()) {} 9100b57cec5SDimitry Andric 9110b57cec5SDimitry Andric bool isKeyOf(const DILexicalBlockFile *RHS) const { 9120b57cec5SDimitry Andric return Scope == RHS->getRawScope() && File == RHS->getRawFile() && 9130b57cec5SDimitry Andric Discriminator == RHS->getDiscriminator(); 9140b57cec5SDimitry Andric } 9150b57cec5SDimitry Andric 9160b57cec5SDimitry Andric unsigned getHashValue() const { 9170b57cec5SDimitry Andric return hash_combine(Scope, File, Discriminator); 9180b57cec5SDimitry Andric } 9190b57cec5SDimitry Andric }; 9200b57cec5SDimitry Andric 9210b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DINamespace> { 9220b57cec5SDimitry Andric Metadata *Scope; 9230b57cec5SDimitry Andric MDString *Name; 9240b57cec5SDimitry Andric bool ExportSymbols; 9250b57cec5SDimitry Andric 9260b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols) 9270b57cec5SDimitry Andric : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {} 9280b57cec5SDimitry Andric MDNodeKeyImpl(const DINamespace *N) 9290b57cec5SDimitry Andric : Scope(N->getRawScope()), Name(N->getRawName()), 9300b57cec5SDimitry Andric ExportSymbols(N->getExportSymbols()) {} 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andric bool isKeyOf(const DINamespace *RHS) const { 9330b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 9340b57cec5SDimitry Andric ExportSymbols == RHS->getExportSymbols(); 9350b57cec5SDimitry Andric } 9360b57cec5SDimitry Andric 937349cc55cSDimitry Andric unsigned getHashValue() const { return hash_combine(Scope, Name); } 9380b57cec5SDimitry Andric }; 9390b57cec5SDimitry Andric 9400b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DICommonBlock> { 9410b57cec5SDimitry Andric Metadata *Scope; 9420b57cec5SDimitry Andric Metadata *Decl; 9430b57cec5SDimitry Andric MDString *Name; 9440b57cec5SDimitry Andric Metadata *File; 9450b57cec5SDimitry Andric unsigned LineNo; 9460b57cec5SDimitry Andric 947349cc55cSDimitry Andric MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name, Metadata *File, 948349cc55cSDimitry Andric unsigned LineNo) 9490b57cec5SDimitry Andric : Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {} 9500b57cec5SDimitry Andric MDNodeKeyImpl(const DICommonBlock *N) 9510b57cec5SDimitry Andric : Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()), 9520b57cec5SDimitry Andric File(N->getRawFile()), LineNo(N->getLineNo()) {} 9530b57cec5SDimitry Andric 9540b57cec5SDimitry Andric bool isKeyOf(const DICommonBlock *RHS) const { 9550b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Decl == RHS->getRawDecl() && 9560b57cec5SDimitry Andric Name == RHS->getRawName() && File == RHS->getRawFile() && 9570b57cec5SDimitry Andric LineNo == RHS->getLineNo(); 9580b57cec5SDimitry Andric } 9590b57cec5SDimitry Andric 9600b57cec5SDimitry Andric unsigned getHashValue() const { 9610b57cec5SDimitry Andric return hash_combine(Scope, Decl, Name, File, LineNo); 9620b57cec5SDimitry Andric } 9630b57cec5SDimitry Andric }; 9640b57cec5SDimitry Andric 9650b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIModule> { 9665ffd83dbSDimitry Andric Metadata *File; 9670b57cec5SDimitry Andric Metadata *Scope; 9680b57cec5SDimitry Andric MDString *Name; 9690b57cec5SDimitry Andric MDString *ConfigurationMacros; 9700b57cec5SDimitry Andric MDString *IncludePath; 9715ffd83dbSDimitry Andric MDString *APINotesFile; 9725ffd83dbSDimitry Andric unsigned LineNo; 973e8d8bef9SDimitry Andric bool IsDecl; 9740b57cec5SDimitry Andric 9755ffd83dbSDimitry Andric MDNodeKeyImpl(Metadata *File, Metadata *Scope, MDString *Name, 9765ffd83dbSDimitry Andric MDString *ConfigurationMacros, MDString *IncludePath, 977e8d8bef9SDimitry Andric MDString *APINotesFile, unsigned LineNo, bool IsDecl) 9785ffd83dbSDimitry Andric : File(File), Scope(Scope), Name(Name), 9795ffd83dbSDimitry Andric ConfigurationMacros(ConfigurationMacros), IncludePath(IncludePath), 980e8d8bef9SDimitry Andric APINotesFile(APINotesFile), LineNo(LineNo), IsDecl(IsDecl) {} 9810b57cec5SDimitry Andric MDNodeKeyImpl(const DIModule *N) 9825ffd83dbSDimitry Andric : File(N->getRawFile()), Scope(N->getRawScope()), Name(N->getRawName()), 9830b57cec5SDimitry Andric ConfigurationMacros(N->getRawConfigurationMacros()), 9845ffd83dbSDimitry Andric IncludePath(N->getRawIncludePath()), 985e8d8bef9SDimitry Andric APINotesFile(N->getRawAPINotesFile()), LineNo(N->getLineNo()), 986e8d8bef9SDimitry Andric IsDecl(N->getIsDecl()) {} 9870b57cec5SDimitry Andric 9880b57cec5SDimitry Andric bool isKeyOf(const DIModule *RHS) const { 9890b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 9900b57cec5SDimitry Andric ConfigurationMacros == RHS->getRawConfigurationMacros() && 9910b57cec5SDimitry Andric IncludePath == RHS->getRawIncludePath() && 9925ffd83dbSDimitry Andric APINotesFile == RHS->getRawAPINotesFile() && 993e8d8bef9SDimitry Andric File == RHS->getRawFile() && LineNo == RHS->getLineNo() && 994e8d8bef9SDimitry Andric IsDecl == RHS->getIsDecl(); 9950b57cec5SDimitry Andric } 9960b57cec5SDimitry Andric 9970b57cec5SDimitry Andric unsigned getHashValue() const { 9985ffd83dbSDimitry Andric return hash_combine(Scope, Name, ConfigurationMacros, IncludePath); 9990b57cec5SDimitry Andric } 10000b57cec5SDimitry Andric }; 10010b57cec5SDimitry Andric 10020b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DITemplateTypeParameter> { 10030b57cec5SDimitry Andric MDString *Name; 10040b57cec5SDimitry Andric Metadata *Type; 10055ffd83dbSDimitry Andric bool IsDefault; 10060b57cec5SDimitry Andric 10075ffd83dbSDimitry Andric MDNodeKeyImpl(MDString *Name, Metadata *Type, bool IsDefault) 10085ffd83dbSDimitry Andric : Name(Name), Type(Type), IsDefault(IsDefault) {} 10090b57cec5SDimitry Andric MDNodeKeyImpl(const DITemplateTypeParameter *N) 10105ffd83dbSDimitry Andric : Name(N->getRawName()), Type(N->getRawType()), 10115ffd83dbSDimitry Andric IsDefault(N->isDefault()) {} 10120b57cec5SDimitry Andric 10130b57cec5SDimitry Andric bool isKeyOf(const DITemplateTypeParameter *RHS) const { 10145ffd83dbSDimitry Andric return Name == RHS->getRawName() && Type == RHS->getRawType() && 10155ffd83dbSDimitry Andric IsDefault == RHS->isDefault(); 10160b57cec5SDimitry Andric } 10170b57cec5SDimitry Andric 10185ffd83dbSDimitry Andric unsigned getHashValue() const { return hash_combine(Name, Type, IsDefault); } 10190b57cec5SDimitry Andric }; 10200b57cec5SDimitry Andric 10210b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DITemplateValueParameter> { 10220b57cec5SDimitry Andric unsigned Tag; 10230b57cec5SDimitry Andric MDString *Name; 10240b57cec5SDimitry Andric Metadata *Type; 10255ffd83dbSDimitry Andric bool IsDefault; 10260b57cec5SDimitry Andric Metadata *Value; 10270b57cec5SDimitry Andric 10285ffd83dbSDimitry Andric MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, bool IsDefault, 10295ffd83dbSDimitry Andric Metadata *Value) 10305ffd83dbSDimitry Andric : Tag(Tag), Name(Name), Type(Type), IsDefault(IsDefault), Value(Value) {} 10310b57cec5SDimitry Andric MDNodeKeyImpl(const DITemplateValueParameter *N) 10320b57cec5SDimitry Andric : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()), 10335ffd83dbSDimitry Andric IsDefault(N->isDefault()), Value(N->getValue()) {} 10340b57cec5SDimitry Andric 10350b57cec5SDimitry Andric bool isKeyOf(const DITemplateValueParameter *RHS) const { 10360b57cec5SDimitry Andric return Tag == RHS->getTag() && Name == RHS->getRawName() && 10375ffd83dbSDimitry Andric Type == RHS->getRawType() && IsDefault == RHS->isDefault() && 10385ffd83dbSDimitry Andric Value == RHS->getValue(); 10390b57cec5SDimitry Andric } 10400b57cec5SDimitry Andric 10415ffd83dbSDimitry Andric unsigned getHashValue() const { 10425ffd83dbSDimitry Andric return hash_combine(Tag, Name, Type, IsDefault, Value); 10435ffd83dbSDimitry Andric } 10440b57cec5SDimitry Andric }; 10450b57cec5SDimitry Andric 10460b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIGlobalVariable> { 10470b57cec5SDimitry Andric Metadata *Scope; 10480b57cec5SDimitry Andric MDString *Name; 10490b57cec5SDimitry Andric MDString *LinkageName; 10500b57cec5SDimitry Andric Metadata *File; 10510b57cec5SDimitry Andric unsigned Line; 10520b57cec5SDimitry Andric Metadata *Type; 10530b57cec5SDimitry Andric bool IsLocalToUnit; 10540b57cec5SDimitry Andric bool IsDefinition; 10550b57cec5SDimitry Andric Metadata *StaticDataMemberDeclaration; 10560b57cec5SDimitry Andric Metadata *TemplateParams; 10570b57cec5SDimitry Andric uint32_t AlignInBits; 1058349cc55cSDimitry Andric Metadata *Annotations; 10590b57cec5SDimitry Andric 10600b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, 10610b57cec5SDimitry Andric Metadata *File, unsigned Line, Metadata *Type, 10620b57cec5SDimitry Andric bool IsLocalToUnit, bool IsDefinition, 10630b57cec5SDimitry Andric Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams, 1064349cc55cSDimitry Andric uint32_t AlignInBits, Metadata *Annotations) 10650b57cec5SDimitry Andric : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), 10660b57cec5SDimitry Andric Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), 10670b57cec5SDimitry Andric IsDefinition(IsDefinition), 10680b57cec5SDimitry Andric StaticDataMemberDeclaration(StaticDataMemberDeclaration), 1069349cc55cSDimitry Andric TemplateParams(TemplateParams), AlignInBits(AlignInBits), 1070349cc55cSDimitry Andric Annotations(Annotations) {} 10710b57cec5SDimitry Andric MDNodeKeyImpl(const DIGlobalVariable *N) 10720b57cec5SDimitry Andric : Scope(N->getRawScope()), Name(N->getRawName()), 10730b57cec5SDimitry Andric LinkageName(N->getRawLinkageName()), File(N->getRawFile()), 10740b57cec5SDimitry Andric Line(N->getLine()), Type(N->getRawType()), 10750b57cec5SDimitry Andric IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), 10760b57cec5SDimitry Andric StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()), 10770b57cec5SDimitry Andric TemplateParams(N->getRawTemplateParams()), 1078349cc55cSDimitry Andric AlignInBits(N->getAlignInBits()), Annotations(N->getRawAnnotations()) {} 10790b57cec5SDimitry Andric 10800b57cec5SDimitry Andric bool isKeyOf(const DIGlobalVariable *RHS) const { 10810b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 10820b57cec5SDimitry Andric LinkageName == RHS->getRawLinkageName() && 10830b57cec5SDimitry Andric File == RHS->getRawFile() && Line == RHS->getLine() && 10840b57cec5SDimitry Andric Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() && 10850b57cec5SDimitry Andric IsDefinition == RHS->isDefinition() && 10860b57cec5SDimitry Andric StaticDataMemberDeclaration == 10870b57cec5SDimitry Andric RHS->getRawStaticDataMemberDeclaration() && 10880b57cec5SDimitry Andric TemplateParams == RHS->getRawTemplateParams() && 1089349cc55cSDimitry Andric AlignInBits == RHS->getAlignInBits() && 1090349cc55cSDimitry Andric Annotations == RHS->getRawAnnotations(); 10910b57cec5SDimitry Andric } 10920b57cec5SDimitry Andric 10930b57cec5SDimitry Andric unsigned getHashValue() const { 10940b57cec5SDimitry Andric // We do not use AlignInBits in hashing function here on purpose: 10950b57cec5SDimitry Andric // in most cases this param for local variable is zero (for function param 10960b57cec5SDimitry Andric // it is always zero). This leads to lots of hash collisions and errors on 10970b57cec5SDimitry Andric // cases with lots of similar variables. 10980b57cec5SDimitry Andric // clang/test/CodeGen/debug-info-257-args.c is an example of this problem, 10990b57cec5SDimitry Andric // generated IR is random for each run and test fails with Align included. 11000b57cec5SDimitry Andric // TODO: make hashing work fine with such situations 11010b57cec5SDimitry Andric return hash_combine(Scope, Name, LinkageName, File, Line, Type, 11020b57cec5SDimitry Andric IsLocalToUnit, IsDefinition, /* AlignInBits, */ 1103349cc55cSDimitry Andric StaticDataMemberDeclaration, Annotations); 11040b57cec5SDimitry Andric } 11050b57cec5SDimitry Andric }; 11060b57cec5SDimitry Andric 11070b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DILocalVariable> { 11080b57cec5SDimitry Andric Metadata *Scope; 11090b57cec5SDimitry Andric MDString *Name; 11100b57cec5SDimitry Andric Metadata *File; 11110b57cec5SDimitry Andric unsigned Line; 11120b57cec5SDimitry Andric Metadata *Type; 11130b57cec5SDimitry Andric unsigned Arg; 11140b57cec5SDimitry Andric unsigned Flags; 11150b57cec5SDimitry Andric uint32_t AlignInBits; 1116349cc55cSDimitry Andric Metadata *Annotations; 11170b57cec5SDimitry Andric 11180b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, 11190b57cec5SDimitry Andric Metadata *Type, unsigned Arg, unsigned Flags, 1120349cc55cSDimitry Andric uint32_t AlignInBits, Metadata *Annotations) 11210b57cec5SDimitry Andric : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg), 1122349cc55cSDimitry Andric Flags(Flags), AlignInBits(AlignInBits), Annotations(Annotations) {} 11230b57cec5SDimitry Andric MDNodeKeyImpl(const DILocalVariable *N) 11240b57cec5SDimitry Andric : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), 11250b57cec5SDimitry Andric Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()), 1126349cc55cSDimitry Andric Flags(N->getFlags()), AlignInBits(N->getAlignInBits()), 1127349cc55cSDimitry Andric Annotations(N->getRawAnnotations()) {} 11280b57cec5SDimitry Andric 11290b57cec5SDimitry Andric bool isKeyOf(const DILocalVariable *RHS) const { 11300b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 11310b57cec5SDimitry Andric File == RHS->getRawFile() && Line == RHS->getLine() && 11320b57cec5SDimitry Andric Type == RHS->getRawType() && Arg == RHS->getArg() && 1133349cc55cSDimitry Andric Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits() && 1134349cc55cSDimitry Andric Annotations == RHS->getRawAnnotations(); 11350b57cec5SDimitry Andric } 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andric unsigned getHashValue() const { 11380b57cec5SDimitry Andric // We do not use AlignInBits in hashing function here on purpose: 11390b57cec5SDimitry Andric // in most cases this param for local variable is zero (for function param 11400b57cec5SDimitry Andric // it is always zero). This leads to lots of hash collisions and errors on 11410b57cec5SDimitry Andric // cases with lots of similar variables. 11420b57cec5SDimitry Andric // clang/test/CodeGen/debug-info-257-args.c is an example of this problem, 11430b57cec5SDimitry Andric // generated IR is random for each run and test fails with Align included. 11440b57cec5SDimitry Andric // TODO: make hashing work fine with such situations 1145349cc55cSDimitry Andric return hash_combine(Scope, Name, File, Line, Type, Arg, Flags, Annotations); 11460b57cec5SDimitry Andric } 11470b57cec5SDimitry Andric }; 11480b57cec5SDimitry Andric 11490b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DILabel> { 11500b57cec5SDimitry Andric Metadata *Scope; 11510b57cec5SDimitry Andric MDString *Name; 11520b57cec5SDimitry Andric Metadata *File; 11530b57cec5SDimitry Andric unsigned Line; 11540b57cec5SDimitry Andric 11550b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line) 11560b57cec5SDimitry Andric : Scope(Scope), Name(Name), File(File), Line(Line) {} 11570b57cec5SDimitry Andric MDNodeKeyImpl(const DILabel *N) 11580b57cec5SDimitry Andric : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), 11590b57cec5SDimitry Andric Line(N->getLine()) {} 11600b57cec5SDimitry Andric 11610b57cec5SDimitry Andric bool isKeyOf(const DILabel *RHS) const { 11620b57cec5SDimitry Andric return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 11630b57cec5SDimitry Andric File == RHS->getRawFile() && Line == RHS->getLine(); 11640b57cec5SDimitry Andric } 11650b57cec5SDimitry Andric 11660b57cec5SDimitry Andric /// Using name and line to get hash value. It should already be mostly unique. 1167349cc55cSDimitry Andric unsigned getHashValue() const { return hash_combine(Scope, Name, Line); } 11680b57cec5SDimitry Andric }; 11690b57cec5SDimitry Andric 11700b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIExpression> { 11710b57cec5SDimitry Andric ArrayRef<uint64_t> Elements; 11720b57cec5SDimitry Andric 11730b57cec5SDimitry Andric MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {} 11740b57cec5SDimitry Andric MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {} 11750b57cec5SDimitry Andric 11760b57cec5SDimitry Andric bool isKeyOf(const DIExpression *RHS) const { 11770b57cec5SDimitry Andric return Elements == RHS->getElements(); 11780b57cec5SDimitry Andric } 11790b57cec5SDimitry Andric 11800b57cec5SDimitry Andric unsigned getHashValue() const { 11810b57cec5SDimitry Andric return hash_combine_range(Elements.begin(), Elements.end()); 11820b57cec5SDimitry Andric } 11830b57cec5SDimitry Andric }; 11840b57cec5SDimitry Andric 11850b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> { 11860b57cec5SDimitry Andric Metadata *Variable; 11870b57cec5SDimitry Andric Metadata *Expression; 11880b57cec5SDimitry Andric 11890b57cec5SDimitry Andric MDNodeKeyImpl(Metadata *Variable, Metadata *Expression) 11900b57cec5SDimitry Andric : Variable(Variable), Expression(Expression) {} 11910b57cec5SDimitry Andric MDNodeKeyImpl(const DIGlobalVariableExpression *N) 11920b57cec5SDimitry Andric : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {} 11930b57cec5SDimitry Andric 11940b57cec5SDimitry Andric bool isKeyOf(const DIGlobalVariableExpression *RHS) const { 11950b57cec5SDimitry Andric return Variable == RHS->getRawVariable() && 11960b57cec5SDimitry Andric Expression == RHS->getRawExpression(); 11970b57cec5SDimitry Andric } 11980b57cec5SDimitry Andric 11990b57cec5SDimitry Andric unsigned getHashValue() const { return hash_combine(Variable, Expression); } 12000b57cec5SDimitry Andric }; 12010b57cec5SDimitry Andric 12020b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIObjCProperty> { 12030b57cec5SDimitry Andric MDString *Name; 12040b57cec5SDimitry Andric Metadata *File; 12050b57cec5SDimitry Andric unsigned Line; 12060b57cec5SDimitry Andric MDString *GetterName; 12070b57cec5SDimitry Andric MDString *SetterName; 12080b57cec5SDimitry Andric unsigned Attributes; 12090b57cec5SDimitry Andric Metadata *Type; 12100b57cec5SDimitry Andric 12110b57cec5SDimitry Andric MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line, 12120b57cec5SDimitry Andric MDString *GetterName, MDString *SetterName, unsigned Attributes, 12130b57cec5SDimitry Andric Metadata *Type) 12140b57cec5SDimitry Andric : Name(Name), File(File), Line(Line), GetterName(GetterName), 12150b57cec5SDimitry Andric SetterName(SetterName), Attributes(Attributes), Type(Type) {} 12160b57cec5SDimitry Andric MDNodeKeyImpl(const DIObjCProperty *N) 12170b57cec5SDimitry Andric : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), 12180b57cec5SDimitry Andric GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()), 12190b57cec5SDimitry Andric Attributes(N->getAttributes()), Type(N->getRawType()) {} 12200b57cec5SDimitry Andric 12210b57cec5SDimitry Andric bool isKeyOf(const DIObjCProperty *RHS) const { 12220b57cec5SDimitry Andric return Name == RHS->getRawName() && File == RHS->getRawFile() && 12230b57cec5SDimitry Andric Line == RHS->getLine() && GetterName == RHS->getRawGetterName() && 12240b57cec5SDimitry Andric SetterName == RHS->getRawSetterName() && 12250b57cec5SDimitry Andric Attributes == RHS->getAttributes() && Type == RHS->getRawType(); 12260b57cec5SDimitry Andric } 12270b57cec5SDimitry Andric 12280b57cec5SDimitry Andric unsigned getHashValue() const { 12290b57cec5SDimitry Andric return hash_combine(Name, File, Line, GetterName, SetterName, Attributes, 12300b57cec5SDimitry Andric Type); 12310b57cec5SDimitry Andric } 12320b57cec5SDimitry Andric }; 12330b57cec5SDimitry Andric 12340b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIImportedEntity> { 12350b57cec5SDimitry Andric unsigned Tag; 12360b57cec5SDimitry Andric Metadata *Scope; 12370b57cec5SDimitry Andric Metadata *Entity; 12380b57cec5SDimitry Andric Metadata *File; 12390b57cec5SDimitry Andric unsigned Line; 12400b57cec5SDimitry Andric MDString *Name; 1241349cc55cSDimitry Andric Metadata *Elements; 12420b57cec5SDimitry Andric 12430b57cec5SDimitry Andric MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File, 1244349cc55cSDimitry Andric unsigned Line, MDString *Name, Metadata *Elements) 12450b57cec5SDimitry Andric : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line), 1246349cc55cSDimitry Andric Name(Name), Elements(Elements) {} 12470b57cec5SDimitry Andric MDNodeKeyImpl(const DIImportedEntity *N) 12480b57cec5SDimitry Andric : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()), 1249349cc55cSDimitry Andric File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()), 1250349cc55cSDimitry Andric Elements(N->getRawElements()) {} 12510b57cec5SDimitry Andric 12520b57cec5SDimitry Andric bool isKeyOf(const DIImportedEntity *RHS) const { 12530b57cec5SDimitry Andric return Tag == RHS->getTag() && Scope == RHS->getRawScope() && 12540b57cec5SDimitry Andric Entity == RHS->getRawEntity() && File == RHS->getFile() && 1255349cc55cSDimitry Andric Line == RHS->getLine() && Name == RHS->getRawName() && 1256349cc55cSDimitry Andric Elements == RHS->getRawElements(); 12570b57cec5SDimitry Andric } 12580b57cec5SDimitry Andric 12590b57cec5SDimitry Andric unsigned getHashValue() const { 1260349cc55cSDimitry Andric return hash_combine(Tag, Scope, Entity, File, Line, Name, Elements); 12610b57cec5SDimitry Andric } 12620b57cec5SDimitry Andric }; 12630b57cec5SDimitry Andric 12640b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIMacro> { 12650b57cec5SDimitry Andric unsigned MIType; 12660b57cec5SDimitry Andric unsigned Line; 12670b57cec5SDimitry Andric MDString *Name; 12680b57cec5SDimitry Andric MDString *Value; 12690b57cec5SDimitry Andric 12700b57cec5SDimitry Andric MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value) 12710b57cec5SDimitry Andric : MIType(MIType), Line(Line), Name(Name), Value(Value) {} 12720b57cec5SDimitry Andric MDNodeKeyImpl(const DIMacro *N) 12730b57cec5SDimitry Andric : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()), 12740b57cec5SDimitry Andric Value(N->getRawValue()) {} 12750b57cec5SDimitry Andric 12760b57cec5SDimitry Andric bool isKeyOf(const DIMacro *RHS) const { 12770b57cec5SDimitry Andric return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && 12780b57cec5SDimitry Andric Name == RHS->getRawName() && Value == RHS->getRawValue(); 12790b57cec5SDimitry Andric } 12800b57cec5SDimitry Andric 12810b57cec5SDimitry Andric unsigned getHashValue() const { 12820b57cec5SDimitry Andric return hash_combine(MIType, Line, Name, Value); 12830b57cec5SDimitry Andric } 12840b57cec5SDimitry Andric }; 12850b57cec5SDimitry Andric 12860b57cec5SDimitry Andric template <> struct MDNodeKeyImpl<DIMacroFile> { 12870b57cec5SDimitry Andric unsigned MIType; 12880b57cec5SDimitry Andric unsigned Line; 12890b57cec5SDimitry Andric Metadata *File; 12900b57cec5SDimitry Andric Metadata *Elements; 12910b57cec5SDimitry Andric 12920b57cec5SDimitry Andric MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File, 12930b57cec5SDimitry Andric Metadata *Elements) 12940b57cec5SDimitry Andric : MIType(MIType), Line(Line), File(File), Elements(Elements) {} 12950b57cec5SDimitry Andric MDNodeKeyImpl(const DIMacroFile *N) 12960b57cec5SDimitry Andric : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()), 12970b57cec5SDimitry Andric Elements(N->getRawElements()) {} 12980b57cec5SDimitry Andric 12990b57cec5SDimitry Andric bool isKeyOf(const DIMacroFile *RHS) const { 13000b57cec5SDimitry Andric return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && 13010b57cec5SDimitry Andric File == RHS->getRawFile() && Elements == RHS->getRawElements(); 13020b57cec5SDimitry Andric } 13030b57cec5SDimitry Andric 13040b57cec5SDimitry Andric unsigned getHashValue() const { 13050b57cec5SDimitry Andric return hash_combine(MIType, Line, File, Elements); 13060b57cec5SDimitry Andric } 13070b57cec5SDimitry Andric }; 13080b57cec5SDimitry Andric 1309*5f757f3fSDimitry Andric // DIArgLists are not MDNodes, but we still want to unique them in a DenseSet 1310*5f757f3fSDimitry Andric // based on a hash of their arguments. 1311*5f757f3fSDimitry Andric struct DIArgListKeyInfo { 1312fe6060f1SDimitry Andric ArrayRef<ValueAsMetadata *> Args; 1313fe6060f1SDimitry Andric 1314*5f757f3fSDimitry Andric DIArgListKeyInfo(ArrayRef<ValueAsMetadata *> Args) : Args(Args) {} 1315*5f757f3fSDimitry Andric DIArgListKeyInfo(const DIArgList *N) : Args(N->getArgs()) {} 1316fe6060f1SDimitry Andric 1317fe6060f1SDimitry Andric bool isKeyOf(const DIArgList *RHS) const { return Args == RHS->getArgs(); } 1318fe6060f1SDimitry Andric 1319fe6060f1SDimitry Andric unsigned getHashValue() const { 1320fe6060f1SDimitry Andric return hash_combine_range(Args.begin(), Args.end()); 1321fe6060f1SDimitry Andric } 1322fe6060f1SDimitry Andric }; 1323fe6060f1SDimitry Andric 1324*5f757f3fSDimitry Andric /// DenseMapInfo for DIArgList. 1325*5f757f3fSDimitry Andric struct DIArgListInfo { 1326*5f757f3fSDimitry Andric using KeyTy = DIArgListKeyInfo; 1327*5f757f3fSDimitry Andric 1328*5f757f3fSDimitry Andric static inline DIArgList *getEmptyKey() { 1329*5f757f3fSDimitry Andric return DenseMapInfo<DIArgList *>::getEmptyKey(); 1330*5f757f3fSDimitry Andric } 1331*5f757f3fSDimitry Andric 1332*5f757f3fSDimitry Andric static inline DIArgList *getTombstoneKey() { 1333*5f757f3fSDimitry Andric return DenseMapInfo<DIArgList *>::getTombstoneKey(); 1334*5f757f3fSDimitry Andric } 1335*5f757f3fSDimitry Andric 1336*5f757f3fSDimitry Andric static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); } 1337*5f757f3fSDimitry Andric 1338*5f757f3fSDimitry Andric static unsigned getHashValue(const DIArgList *N) { 1339*5f757f3fSDimitry Andric return KeyTy(N).getHashValue(); 1340*5f757f3fSDimitry Andric } 1341*5f757f3fSDimitry Andric 1342*5f757f3fSDimitry Andric static bool isEqual(const KeyTy &LHS, const DIArgList *RHS) { 1343*5f757f3fSDimitry Andric if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 1344*5f757f3fSDimitry Andric return false; 1345*5f757f3fSDimitry Andric return LHS.isKeyOf(RHS); 1346*5f757f3fSDimitry Andric } 1347*5f757f3fSDimitry Andric 1348*5f757f3fSDimitry Andric static bool isEqual(const DIArgList *LHS, const DIArgList *RHS) { 1349*5f757f3fSDimitry Andric return LHS == RHS; 1350*5f757f3fSDimitry Andric } 1351*5f757f3fSDimitry Andric }; 1352*5f757f3fSDimitry Andric 13530b57cec5SDimitry Andric /// DenseMapInfo for MDNode subclasses. 13540b57cec5SDimitry Andric template <class NodeTy> struct MDNodeInfo { 13550b57cec5SDimitry Andric using KeyTy = MDNodeKeyImpl<NodeTy>; 13560b57cec5SDimitry Andric using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>; 13570b57cec5SDimitry Andric 13580b57cec5SDimitry Andric static inline NodeTy *getEmptyKey() { 13590b57cec5SDimitry Andric return DenseMapInfo<NodeTy *>::getEmptyKey(); 13600b57cec5SDimitry Andric } 13610b57cec5SDimitry Andric 13620b57cec5SDimitry Andric static inline NodeTy *getTombstoneKey() { 13630b57cec5SDimitry Andric return DenseMapInfo<NodeTy *>::getTombstoneKey(); 13640b57cec5SDimitry Andric } 13650b57cec5SDimitry Andric 13660b57cec5SDimitry Andric static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); } 13670b57cec5SDimitry Andric 13680b57cec5SDimitry Andric static unsigned getHashValue(const NodeTy *N) { 13690b57cec5SDimitry Andric return KeyTy(N).getHashValue(); 13700b57cec5SDimitry Andric } 13710b57cec5SDimitry Andric 13720b57cec5SDimitry Andric static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) { 13730b57cec5SDimitry Andric if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 13740b57cec5SDimitry Andric return false; 13750b57cec5SDimitry Andric return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS); 13760b57cec5SDimitry Andric } 13770b57cec5SDimitry Andric 13780b57cec5SDimitry Andric static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) { 13790b57cec5SDimitry Andric if (LHS == RHS) 13800b57cec5SDimitry Andric return true; 13810b57cec5SDimitry Andric if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 13820b57cec5SDimitry Andric return false; 13830b57cec5SDimitry Andric return SubsetEqualTy::isSubsetEqual(LHS, RHS); 13840b57cec5SDimitry Andric } 13850b57cec5SDimitry Andric }; 13860b57cec5SDimitry Andric 13870b57cec5SDimitry Andric #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>; 13880b57cec5SDimitry Andric #include "llvm/IR/Metadata.def" 13890b57cec5SDimitry Andric 1390e8d8bef9SDimitry Andric /// Multimap-like storage for metadata attachments. 1391e8d8bef9SDimitry Andric class MDAttachments { 1392e8d8bef9SDimitry Andric public: 1393e8d8bef9SDimitry Andric struct Attachment { 1394e8d8bef9SDimitry Andric unsigned MDKind; 1395e8d8bef9SDimitry Andric TrackingMDNodeRef Node; 1396e8d8bef9SDimitry Andric }; 1397e8d8bef9SDimitry Andric 1398e8d8bef9SDimitry Andric private: 1399e8d8bef9SDimitry Andric SmallVector<Attachment, 1> Attachments; 14000b57cec5SDimitry Andric 14010b57cec5SDimitry Andric public: 14020b57cec5SDimitry Andric bool empty() const { return Attachments.empty(); } 14030b57cec5SDimitry Andric size_t size() const { return Attachments.size(); } 14040b57cec5SDimitry Andric 1405e8d8bef9SDimitry Andric /// Returns the first attachment with the given ID or nullptr if no such 1406e8d8bef9SDimitry Andric /// attachment exists. 14070b57cec5SDimitry Andric MDNode *lookup(unsigned ID) const; 14080b57cec5SDimitry Andric 14090b57cec5SDimitry Andric /// Appends all attachments with the given ID to \c Result in insertion order. 14100b57cec5SDimitry Andric /// If the global has no attachments with the given ID, or if ID is invalid, 14110b57cec5SDimitry Andric /// leaves Result unchanged. 14120b57cec5SDimitry Andric void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const; 14130b57cec5SDimitry Andric 14140b57cec5SDimitry Andric /// Appends all attachments for the global to \c Result, sorting by attachment 14150b57cec5SDimitry Andric /// ID. Attachments with the same ID appear in insertion order. This function 14160b57cec5SDimitry Andric /// does \em not clear \c Result. 14170b57cec5SDimitry Andric void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; 1418e8d8bef9SDimitry Andric 1419e8d8bef9SDimitry Andric /// Set an attachment to a particular node. 1420e8d8bef9SDimitry Andric /// 1421e8d8bef9SDimitry Andric /// Set the \c ID attachment to \c MD, replacing the current attachments at \c 1422e8d8bef9SDimitry Andric /// ID (if anyway). 1423e8d8bef9SDimitry Andric void set(unsigned ID, MDNode *MD); 1424e8d8bef9SDimitry Andric 1425e8d8bef9SDimitry Andric /// Adds an attachment to a particular node. 1426e8d8bef9SDimitry Andric void insert(unsigned ID, MDNode &MD); 1427e8d8bef9SDimitry Andric 1428e8d8bef9SDimitry Andric /// Remove attachments with the given ID. 1429e8d8bef9SDimitry Andric /// 1430e8d8bef9SDimitry Andric /// Remove the attachments at \c ID, if any. 1431e8d8bef9SDimitry Andric bool erase(unsigned ID); 1432e8d8bef9SDimitry Andric 1433e8d8bef9SDimitry Andric /// Erase matching attachments. 1434e8d8bef9SDimitry Andric /// 1435e8d8bef9SDimitry Andric /// Erases all attachments matching the \c shouldRemove predicate. 1436e8d8bef9SDimitry Andric template <class PredTy> void remove_if(PredTy shouldRemove) { 1437e8d8bef9SDimitry Andric llvm::erase_if(Attachments, shouldRemove); 1438e8d8bef9SDimitry Andric } 14390b57cec5SDimitry Andric }; 14400b57cec5SDimitry Andric 14410b57cec5SDimitry Andric class LLVMContextImpl { 14420b57cec5SDimitry Andric public: 14430b57cec5SDimitry Andric /// OwnedModules - The set of modules instantiated in this context, and which 14440b57cec5SDimitry Andric /// will be automatically deleted if this context is deleted. 14450b57cec5SDimitry Andric SmallPtrSet<Module *, 4> OwnedModules; 14460b57cec5SDimitry Andric 14475ffd83dbSDimitry Andric /// The main remark streamer used by all the other streamers (e.g. IR, MIR, 14485ffd83dbSDimitry Andric /// frontends, etc.). This should only be used by the specific streamers, and 14495ffd83dbSDimitry Andric /// never directly. 14505ffd83dbSDimitry Andric std::unique_ptr<remarks::RemarkStreamer> MainRemarkStreamer; 14515ffd83dbSDimitry Andric 14520b57cec5SDimitry Andric std::unique_ptr<DiagnosticHandler> DiagHandler; 14530b57cec5SDimitry Andric bool RespectDiagnosticFilters = false; 14540b57cec5SDimitry Andric bool DiagnosticsHotnessRequested = false; 1455e8d8bef9SDimitry Andric /// The minimum hotness value a diagnostic needs in order to be included in 1456e8d8bef9SDimitry Andric /// optimization diagnostics. 1457e8d8bef9SDimitry Andric /// 1458e8d8bef9SDimitry Andric /// The threshold is an Optional value, which maps to one of the 3 states: 1459e8d8bef9SDimitry Andric /// 1). 0 => threshold disabled. All emarks will be printed. 1460e8d8bef9SDimitry Andric /// 2). positive int => manual threshold by user. Remarks with hotness exceed 1461e8d8bef9SDimitry Andric /// threshold will be printed. 1462e8d8bef9SDimitry Andric /// 3). None => 'auto' threshold by user. The actual value is not 1463e8d8bef9SDimitry Andric /// available at command line, but will be synced with 1464e8d8bef9SDimitry Andric /// hotness threhold from profile summary during 1465e8d8bef9SDimitry Andric /// compilation. 1466e8d8bef9SDimitry Andric /// 1467e8d8bef9SDimitry Andric /// State 1 and 2 are considered as terminal states. State transition is 1468e8d8bef9SDimitry Andric /// only allowed from 3 to 2, when the threshold is first synced with profile 1469e8d8bef9SDimitry Andric /// summary. This ensures that the threshold is set only once and stays 1470e8d8bef9SDimitry Andric /// constant. 1471e8d8bef9SDimitry Andric /// 1472e8d8bef9SDimitry Andric /// If threshold option is not specified, it is disabled (0) by default. 1473bdd1243dSDimitry Andric std::optional<uint64_t> DiagnosticsHotnessThreshold = 0; 1474e8d8bef9SDimitry Andric 147581ad6265SDimitry Andric /// The percentage of difference between profiling branch weights and 1476bdd1243dSDimitry Andric /// llvm.expect branch weights to tolerate when emiting MisExpect diagnostics 1477bdd1243dSDimitry Andric std::optional<uint32_t> DiagnosticsMisExpectTolerance = 0; 147881ad6265SDimitry Andric bool MisExpectWarningRequested = false; 147981ad6265SDimitry Andric 14805ffd83dbSDimitry Andric /// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter. 14815ffd83dbSDimitry Andric std::unique_ptr<LLVMRemarkStreamer> LLVMRS; 14820b57cec5SDimitry Andric 14830b57cec5SDimitry Andric LLVMContext::YieldCallbackTy YieldCallback = nullptr; 14840b57cec5SDimitry Andric void *YieldOpaqueHandle = nullptr; 14850b57cec5SDimitry Andric 148681ad6265SDimitry Andric DenseMap<const Value *, ValueName *> ValueNames; 148781ad6265SDimitry Andric 148806c3fb27SDimitry Andric DenseMap<unsigned, std::unique_ptr<ConstantInt>> IntZeroConstants; 148906c3fb27SDimitry Andric DenseMap<unsigned, std::unique_ptr<ConstantInt>> IntOneConstants; 1490*5f757f3fSDimitry Andric DenseMap<APInt, std::unique_ptr<ConstantInt>> IntConstants; 14910b57cec5SDimitry Andric 1492*5f757f3fSDimitry Andric DenseMap<APFloat, std::unique_ptr<ConstantFP>> FPConstants; 14930b57cec5SDimitry Andric 14940b57cec5SDimitry Andric FoldingSet<AttributeImpl> AttrsSet; 14950b57cec5SDimitry Andric FoldingSet<AttributeListImpl> AttrsLists; 14960b57cec5SDimitry Andric FoldingSet<AttributeSetNode> AttrsSetNodes; 14970b57cec5SDimitry Andric 14980b57cec5SDimitry Andric StringMap<MDString, BumpPtrAllocator> MDStringCache; 14990b57cec5SDimitry Andric DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata; 15000b57cec5SDimitry Andric DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues; 1501*5f757f3fSDimitry Andric DenseSet<DIArgList *, DIArgListInfo> DIArgLists; 15020b57cec5SDimitry Andric 15030b57cec5SDimitry Andric #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \ 15040b57cec5SDimitry Andric DenseSet<CLASS *, CLASS##Info> CLASS##s; 15050b57cec5SDimitry Andric #include "llvm/IR/Metadata.def" 15060b57cec5SDimitry Andric 15070b57cec5SDimitry Andric // Optional map for looking up composite types by identifier. 1508bdd1243dSDimitry Andric std::optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap; 15090b57cec5SDimitry Andric 15100b57cec5SDimitry Andric // MDNodes may be uniqued or not uniqued. When they're not uniqued, they 15110b57cec5SDimitry Andric // aren't in the MDNodeSet, but they're still shared between objects, so no 15120b57cec5SDimitry Andric // one object can destroy them. Keep track of them here so we can delete 15130b57cec5SDimitry Andric // them on context teardown. 15140b57cec5SDimitry Andric std::vector<MDNode *> DistinctMDNodes; 15150b57cec5SDimitry Andric 15160b57cec5SDimitry Andric DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants; 15170b57cec5SDimitry Andric 15180b57cec5SDimitry Andric using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>; 15190b57cec5SDimitry Andric ArrayConstantsTy ArrayConstants; 15200b57cec5SDimitry Andric 15210b57cec5SDimitry Andric using StructConstantsTy = ConstantUniqueMap<ConstantStruct>; 15220b57cec5SDimitry Andric StructConstantsTy StructConstants; 15230b57cec5SDimitry Andric 15240b57cec5SDimitry Andric using VectorConstantsTy = ConstantUniqueMap<ConstantVector>; 15250b57cec5SDimitry Andric VectorConstantsTy VectorConstants; 15260b57cec5SDimitry Andric 15270b57cec5SDimitry Andric DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants; 15280b57cec5SDimitry Andric 1529bdd1243dSDimitry Andric DenseMap<TargetExtType *, std::unique_ptr<ConstantTargetNone>> CTNConstants; 1530bdd1243dSDimitry Andric 15310b57cec5SDimitry Andric DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants; 15320b57cec5SDimitry Andric 1533e8d8bef9SDimitry Andric DenseMap<Type *, std::unique_ptr<PoisonValue>> PVConstants; 1534e8d8bef9SDimitry Andric 1535e8d8bef9SDimitry Andric StringMap<std::unique_ptr<ConstantDataSequential>> CDSConstants; 15360b57cec5SDimitry Andric 15370b57cec5SDimitry Andric DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *> 15380b57cec5SDimitry Andric BlockAddresses; 1539e8d8bef9SDimitry Andric 1540e8d8bef9SDimitry Andric DenseMap<const GlobalValue *, DSOLocalEquivalent *> DSOLocalEquivalents; 1541e8d8bef9SDimitry Andric 15420eae32dcSDimitry Andric DenseMap<const GlobalValue *, NoCFIValue *> NoCFIValues; 15430eae32dcSDimitry Andric 15440b57cec5SDimitry Andric ConstantUniqueMap<ConstantExpr> ExprConstants; 15450b57cec5SDimitry Andric 15460b57cec5SDimitry Andric ConstantUniqueMap<InlineAsm> InlineAsms; 15470b57cec5SDimitry Andric 15480b57cec5SDimitry Andric ConstantInt *TheTrueVal = nullptr; 15490b57cec5SDimitry Andric ConstantInt *TheFalseVal = nullptr; 15500b57cec5SDimitry Andric 15510b57cec5SDimitry Andric // Basic type instances. 15525ffd83dbSDimitry Andric Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy, 15535ffd83dbSDimitry Andric TokenTy; 1554e8d8bef9SDimitry Andric Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy, X86_AMXTy; 15550b57cec5SDimitry Andric IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; 15560b57cec5SDimitry Andric 155781ad6265SDimitry Andric std::unique_ptr<ConstantTokenNone> TheNoneToken; 155881ad6265SDimitry Andric 15590b57cec5SDimitry Andric BumpPtrAllocator Alloc; 15600b57cec5SDimitry Andric UniqueStringSaver Saver{Alloc}; 15610b57cec5SDimitry Andric 15620b57cec5SDimitry Andric DenseMap<unsigned, IntegerType *> IntegerTypes; 15630b57cec5SDimitry Andric 15640b57cec5SDimitry Andric using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>; 15650b57cec5SDimitry Andric FunctionTypeSet FunctionTypes; 15660b57cec5SDimitry Andric using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>; 15670b57cec5SDimitry Andric StructTypeSet AnonStructTypes; 15680b57cec5SDimitry Andric StringMap<StructType *> NamedStructTypes; 15690b57cec5SDimitry Andric unsigned NamedStructTypesUniqueID = 0; 15700b57cec5SDimitry Andric 1571bdd1243dSDimitry Andric using TargetExtTypeSet = DenseSet<TargetExtType *, TargetExtTypeKeyInfo>; 1572bdd1243dSDimitry Andric TargetExtTypeSet TargetExtTypes; 1573bdd1243dSDimitry Andric 15740b57cec5SDimitry Andric DenseMap<std::pair<Type *, uint64_t>, ArrayType *> ArrayTypes; 15750b57cec5SDimitry Andric DenseMap<std::pair<Type *, ElementCount>, VectorType *> VectorTypes; 157606c3fb27SDimitry Andric PointerType *AS0PointerType = nullptr; // AddrSpace = 0 157706c3fb27SDimitry Andric DenseMap<unsigned, PointerType *> PointerTypes; 157806c3fb27SDimitry Andric DenseMap<std::pair<Type *, unsigned>, PointerType *> LegacyPointerTypes; 1579bdd1243dSDimitry Andric DenseMap<std::pair<Type *, unsigned>, TypedPointerType *> ASTypedPointerTypes; 15800b57cec5SDimitry Andric 15810b57cec5SDimitry Andric /// ValueHandles - This map keeps track of all of the value handles that are 15820b57cec5SDimitry Andric /// watching a Value*. The Value::HasValueHandle bit is used to know 15830b57cec5SDimitry Andric /// whether or not a value has an entry in this map. 15840b57cec5SDimitry Andric using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>; 15850b57cec5SDimitry Andric ValueHandlesTy ValueHandles; 15860b57cec5SDimitry Andric 15870b57cec5SDimitry Andric /// CustomMDKindNames - Map to hold the metadata string to ID mapping. 15880b57cec5SDimitry Andric StringMap<unsigned> CustomMDKindNames; 15890b57cec5SDimitry Andric 1590e8d8bef9SDimitry Andric /// Collection of metadata used in this context. 1591e8d8bef9SDimitry Andric DenseMap<const Value *, MDAttachments> ValueMetadata; 15920b57cec5SDimitry Andric 1593bdd1243dSDimitry Andric /// Map DIAssignID -> Instructions with that attachment. 1594bdd1243dSDimitry Andric /// Managed by Instruction via Instruction::updateDIAssignIDMapping. 1595bdd1243dSDimitry Andric /// Query using the at:: functions defined in DebugInfo.h. 1596bdd1243dSDimitry Andric DenseMap<DIAssignID *, SmallVector<Instruction *, 1>> AssignmentIDToInstrs; 1597bdd1243dSDimitry Andric 15980b57cec5SDimitry Andric /// Collection of per-GlobalObject sections used in this context. 15990b57cec5SDimitry Andric DenseMap<const GlobalObject *, StringRef> GlobalObjectSections; 16000b57cec5SDimitry Andric 16010b57cec5SDimitry Andric /// Collection of per-GlobalValue partitions used in this context. 16020b57cec5SDimitry Andric DenseMap<const GlobalValue *, StringRef> GlobalValuePartitions; 16030b57cec5SDimitry Andric 160481ad6265SDimitry Andric DenseMap<const GlobalValue *, GlobalValue::SanitizerMetadata> 160581ad6265SDimitry Andric GlobalValueSanitizerMetadata; 160681ad6265SDimitry Andric 16070b57cec5SDimitry Andric /// DiscriminatorTable - This table maps file:line locations to an 16080b57cec5SDimitry Andric /// integer representing the next DWARF path discriminator to assign to 16090b57cec5SDimitry Andric /// instructions in different blocks at the same location. 16100b57cec5SDimitry Andric DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable; 16110b57cec5SDimitry Andric 16120b57cec5SDimitry Andric /// A set of interned tags for operand bundles. The StringMap maps 16130b57cec5SDimitry Andric /// bundle tags to their IDs. 16140b57cec5SDimitry Andric /// 16150b57cec5SDimitry Andric /// \see LLVMContext::getOperandBundleTagID 16160b57cec5SDimitry Andric StringMap<uint32_t> BundleTagCache; 16170b57cec5SDimitry Andric 16180b57cec5SDimitry Andric StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag); 16190b57cec5SDimitry Andric void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const; 16200b57cec5SDimitry Andric uint32_t getOperandBundleTagID(StringRef Tag) const; 16210b57cec5SDimitry Andric 16220b57cec5SDimitry Andric /// A set of interned synchronization scopes. The StringMap maps 16230b57cec5SDimitry Andric /// synchronization scope names to their respective synchronization scope IDs. 16240b57cec5SDimitry Andric StringMap<SyncScope::ID> SSC; 16250b57cec5SDimitry Andric 16260b57cec5SDimitry Andric /// getOrInsertSyncScopeID - Maps synchronization scope name to 16270b57cec5SDimitry Andric /// synchronization scope ID. Every synchronization scope registered with 16280b57cec5SDimitry Andric /// LLVMContext has unique ID except pre-defined ones. 16290b57cec5SDimitry Andric SyncScope::ID getOrInsertSyncScopeID(StringRef SSN); 16300b57cec5SDimitry Andric 16310b57cec5SDimitry Andric /// getSyncScopeNames - Populates client supplied SmallVector with 16320b57cec5SDimitry Andric /// synchronization scope names registered with LLVMContext. Synchronization 16330b57cec5SDimitry Andric /// scope names are ordered by increasing synchronization scope IDs. 16340b57cec5SDimitry Andric void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const; 16350b57cec5SDimitry Andric 16360b57cec5SDimitry Andric /// Maintain the GC name for each function. 16370b57cec5SDimitry Andric /// 16380b57cec5SDimitry Andric /// This saves allocating an additional word in Function for programs which 16390b57cec5SDimitry Andric /// do not use GC (i.e., most programs) at the cost of increased overhead for 16400b57cec5SDimitry Andric /// clients which do use GC. 16410b57cec5SDimitry Andric DenseMap<const Function *, std::string> GCNames; 16420b57cec5SDimitry Andric 16430b57cec5SDimitry Andric /// Flag to indicate if Value (other than GlobalValue) retains their name or 16440b57cec5SDimitry Andric /// not. 16450b57cec5SDimitry Andric bool DiscardValueNames = false; 16460b57cec5SDimitry Andric 16470b57cec5SDimitry Andric LLVMContextImpl(LLVMContext &C); 16480b57cec5SDimitry Andric ~LLVMContextImpl(); 16490b57cec5SDimitry Andric 16500b57cec5SDimitry Andric /// Destroy the ConstantArrays if they are not used. 16510b57cec5SDimitry Andric void dropTriviallyDeadConstantArrays(); 16520b57cec5SDimitry Andric 16530b57cec5SDimitry Andric mutable OptPassGate *OPG = nullptr; 16540b57cec5SDimitry Andric 16550b57cec5SDimitry Andric /// Access the object which can disable optional passes and individual 16560b57cec5SDimitry Andric /// optimizations at compile time. 16570b57cec5SDimitry Andric OptPassGate &getOptPassGate() const; 16580b57cec5SDimitry Andric 16590b57cec5SDimitry Andric /// Set the object which can disable optional passes and individual 16600b57cec5SDimitry Andric /// optimizations at compile time. 16610b57cec5SDimitry Andric /// 16620b57cec5SDimitry Andric /// The lifetime of the object must be guaranteed to extend as long as the 16630b57cec5SDimitry Andric /// LLVMContext is used by compilation. 16640b57cec5SDimitry Andric void setOptPassGate(OptPassGate &); 1665*5f757f3fSDimitry Andric 1666*5f757f3fSDimitry Andric /// Mapping of blocks to collections of "trailing" DPValues. As part of the 1667*5f757f3fSDimitry Andric /// "RemoveDIs" project, debug-info variable location records are going to 1668*5f757f3fSDimitry Andric /// cease being instructions... which raises the problem of where should they 1669*5f757f3fSDimitry Andric /// be recorded when we remove the terminator of a blocks, such as: 1670*5f757f3fSDimitry Andric /// 1671*5f757f3fSDimitry Andric /// %foo = add i32 0, 0 1672*5f757f3fSDimitry Andric /// br label %bar 1673*5f757f3fSDimitry Andric /// 1674*5f757f3fSDimitry Andric /// If the branch is removed, a legitimate transient state while editing a 1675*5f757f3fSDimitry Andric /// block, any debug-records between those two instructions will not have a 1676*5f757f3fSDimitry Andric /// location. Each block thus records any DPValue records that "trail" in 1677*5f757f3fSDimitry Andric /// such a way. These are stored in LLVMContext because typically LLVM only 1678*5f757f3fSDimitry Andric /// edits a small number of blocks at a time, so there's no need to bloat 1679*5f757f3fSDimitry Andric /// BasicBlock with such a data structure. 1680*5f757f3fSDimitry Andric SmallDenseMap<BasicBlock *, DPMarker *> TrailingDPValues; 1681*5f757f3fSDimitry Andric 1682*5f757f3fSDimitry Andric // Set, get and delete operations for TrailingDPValues. 1683*5f757f3fSDimitry Andric void setTrailingDPValues(BasicBlock *B, DPMarker *M) { 1684*5f757f3fSDimitry Andric assert(!TrailingDPValues.count(B)); 1685*5f757f3fSDimitry Andric TrailingDPValues[B] = M; 1686*5f757f3fSDimitry Andric } 1687*5f757f3fSDimitry Andric 1688*5f757f3fSDimitry Andric DPMarker *getTrailingDPValues(BasicBlock *B) { 1689*5f757f3fSDimitry Andric return TrailingDPValues.lookup(B); 1690*5f757f3fSDimitry Andric } 1691*5f757f3fSDimitry Andric 1692*5f757f3fSDimitry Andric void deleteTrailingDPValues(BasicBlock *B) { 1693*5f757f3fSDimitry Andric TrailingDPValues.erase(B); 1694*5f757f3fSDimitry Andric } 16950b57cec5SDimitry Andric }; 16960b57cec5SDimitry Andric 16970b57cec5SDimitry Andric } // end namespace llvm 16980b57cec5SDimitry Andric 16990b57cec5SDimitry Andric #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H 1700