LLVM  mainline
LLVMContextImpl.h
Go to the documentation of this file.
00001 //===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file declares LLVMContextImpl, the opaque implementation 
00011 //  of LLVMContext.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
00016 #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
00017 
00018 #include "AttributeImpl.h"
00019 #include "ConstantsContext.h"
00020 #include "llvm/ADT/APFloat.h"
00021 #include "llvm/ADT/APInt.h"
00022 #include "llvm/ADT/ArrayRef.h"
00023 #include "llvm/ADT/DenseMap.h"
00024 #include "llvm/ADT/DenseSet.h"
00025 #include "llvm/ADT/FoldingSet.h"
00026 #include "llvm/ADT/Hashing.h"
00027 #include "llvm/ADT/SmallPtrSet.h"
00028 #include "llvm/ADT/StringMap.h"
00029 #include "llvm/IR/Constants.h"
00030 #include "llvm/IR/DebugInfoMetadata.h"
00031 #include "llvm/IR/DerivedTypes.h"
00032 #include "llvm/IR/LLVMContext.h"
00033 #include "llvm/IR/Metadata.h"
00034 #include "llvm/IR/ValueHandle.h"
00035 #include <vector>
00036 
00037 namespace llvm {
00038 
00039 class ConstantInt;
00040 class ConstantFP;
00041 class DiagnosticInfoOptimizationRemark;
00042 class DiagnosticInfoOptimizationRemarkMissed;
00043 class DiagnosticInfoOptimizationRemarkAnalysis;
00044 class GCStrategy;
00045 class LLVMContext;
00046 class Type;
00047 class Value;
00048 
00049 struct DenseMapAPIntKeyInfo {
00050   static inline APInt getEmptyKey() {
00051     APInt V(nullptr, 0);
00052     V.VAL = 0;
00053     return V;
00054   }
00055   static inline APInt getTombstoneKey() {
00056     APInt V(nullptr, 0);
00057     V.VAL = 1;
00058     return V;
00059   }
00060   static unsigned getHashValue(const APInt &Key) {
00061     return static_cast<unsigned>(hash_value(Key));
00062   }
00063   static bool isEqual(const APInt &LHS, const APInt &RHS) {
00064     return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
00065   }
00066 };
00067 
00068 struct DenseMapAPFloatKeyInfo {
00069   static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); }
00070   static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); }
00071   static unsigned getHashValue(const APFloat &Key) {
00072     return static_cast<unsigned>(hash_value(Key));
00073   }
00074   static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
00075     return LHS.bitwiseIsEqual(RHS);
00076   }
00077 };
00078 
00079 struct AnonStructTypeKeyInfo {
00080   struct KeyTy {
00081     ArrayRef<Type*> ETypes;
00082     bool isPacked;
00083     KeyTy(const ArrayRef<Type*>& E, bool P) :
00084       ETypes(E), isPacked(P) {}
00085     KeyTy(const StructType *ST)
00086         : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
00087     bool operator==(const KeyTy& that) const {
00088       if (isPacked != that.isPacked)
00089         return false;
00090       if (ETypes != that.ETypes)
00091         return false;
00092       return true;
00093     }
00094     bool operator!=(const KeyTy& that) const {
00095       return !this->operator==(that);
00096     }
00097   };
00098   static inline StructType* getEmptyKey() {
00099     return DenseMapInfo<StructType*>::getEmptyKey();
00100   }
00101   static inline StructType* getTombstoneKey() {
00102     return DenseMapInfo<StructType*>::getTombstoneKey();
00103   }
00104   static unsigned getHashValue(const KeyTy& Key) {
00105     return hash_combine(hash_combine_range(Key.ETypes.begin(),
00106                                            Key.ETypes.end()),
00107                         Key.isPacked);
00108   }
00109   static unsigned getHashValue(const StructType *ST) {
00110     return getHashValue(KeyTy(ST));
00111   }
00112   static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
00113     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
00114       return false;
00115     return LHS == KeyTy(RHS);
00116   }
00117   static bool isEqual(const StructType *LHS, const StructType *RHS) {
00118     return LHS == RHS;
00119   }
00120 };
00121 
00122 struct FunctionTypeKeyInfo {
00123   struct KeyTy {
00124     const Type *ReturnType;
00125     ArrayRef<Type*> Params;
00126     bool isVarArg;
00127     KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
00128       ReturnType(R), Params(P), isVarArg(V) {}
00129     KeyTy(const FunctionType *FT)
00130         : ReturnType(FT->getReturnType()), Params(FT->params()),
00131           isVarArg(FT->isVarArg()) {}
00132     bool operator==(const KeyTy& that) const {
00133       if (ReturnType != that.ReturnType)
00134         return false;
00135       if (isVarArg != that.isVarArg)
00136         return false;
00137       if (Params != that.Params)
00138         return false;
00139       return true;
00140     }
00141     bool operator!=(const KeyTy& that) const {
00142       return !this->operator==(that);
00143     }
00144   };
00145   static inline FunctionType* getEmptyKey() {
00146     return DenseMapInfo<FunctionType*>::getEmptyKey();
00147   }
00148   static inline FunctionType* getTombstoneKey() {
00149     return DenseMapInfo<FunctionType*>::getTombstoneKey();
00150   }
00151   static unsigned getHashValue(const KeyTy& Key) {
00152     return hash_combine(Key.ReturnType,
00153                         hash_combine_range(Key.Params.begin(),
00154                                            Key.Params.end()),
00155                         Key.isVarArg);
00156   }
00157   static unsigned getHashValue(const FunctionType *FT) {
00158     return getHashValue(KeyTy(FT));
00159   }
00160   static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
00161     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
00162       return false;
00163     return LHS == KeyTy(RHS);
00164   }
00165   static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
00166     return LHS == RHS;
00167   }
00168 };
00169 
00170 /// \brief Structure for hashing arbitrary MDNode operands.
00171 class MDNodeOpsKey {
00172   ArrayRef<Metadata *> RawOps;
00173   ArrayRef<MDOperand> Ops;
00174 
00175   unsigned Hash;
00176 
00177 protected:
00178   MDNodeOpsKey(ArrayRef<Metadata *> Ops)
00179       : RawOps(Ops), Hash(calculateHash(Ops)) {}
00180 
00181   template <class NodeTy>
00182   MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
00183       : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
00184 
00185   template <class NodeTy>
00186   bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
00187     if (getHash() != RHS->getHash())
00188       return false;
00189 
00190     assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
00191     return RawOps.empty() ? compareOps(Ops, RHS, Offset)
00192                           : compareOps(RawOps, RHS, Offset);
00193   }
00194 
00195   static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
00196 
00197 private:
00198   template <class T>
00199   static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
00200     if (Ops.size() != RHS->getNumOperands() - Offset)
00201       return false;
00202     return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
00203   }
00204 
00205   static unsigned calculateHash(ArrayRef<Metadata *> Ops);
00206 
00207 public:
00208   unsigned getHash() const { return Hash; }
00209 };
00210 
00211 template <class NodeTy> struct MDNodeKeyImpl;
00212 template <class NodeTy> struct MDNodeInfo;
00213 
00214 /// \brief DenseMapInfo for MDTuple.
00215 ///
00216 /// Note that we don't need the is-function-local bit, since that's implicit in
00217 /// the operands.
00218 template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
00219   MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
00220   MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
00221 
00222   bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
00223 
00224   unsigned getHashValue() const { return getHash(); }
00225 
00226   static unsigned calculateHash(MDTuple *N) {
00227     return MDNodeOpsKey::calculateHash(N);
00228   }
00229 };
00230 
00231 /// \brief DenseMapInfo for MDLocation.
00232 template <> struct MDNodeKeyImpl<MDLocation> {
00233   unsigned Line;
00234   unsigned Column;
00235   Metadata *Scope;
00236   Metadata *InlinedAt;
00237 
00238   MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
00239                 Metadata *InlinedAt)
00240       : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
00241 
00242   MDNodeKeyImpl(const MDLocation *L)
00243       : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
00244         InlinedAt(L->getRawInlinedAt()) {}
00245 
00246   bool isKeyOf(const MDLocation *RHS) const {
00247     return Line == RHS->getLine() && Column == RHS->getColumn() &&
00248            Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
00249   }
00250   unsigned getHashValue() const {
00251     return hash_combine(Line, Column, Scope, InlinedAt);
00252   }
00253 };
00254 
00255 /// \brief DenseMapInfo for GenericDebugNode.
00256 template <> struct MDNodeKeyImpl<GenericDebugNode> : MDNodeOpsKey {
00257   unsigned Tag;
00258   StringRef Header;
00259   MDNodeKeyImpl(unsigned Tag, StringRef Header, ArrayRef<Metadata *> DwarfOps)
00260       : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
00261   MDNodeKeyImpl(const GenericDebugNode *N)
00262       : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getHeader()) {}
00263 
00264   bool isKeyOf(const GenericDebugNode *RHS) const {
00265     return Tag == RHS->getTag() && Header == RHS->getHeader() &&
00266            compareOps(RHS, 1);
00267   }
00268 
00269   unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
00270 
00271   static unsigned calculateHash(GenericDebugNode *N) {
00272     return MDNodeOpsKey::calculateHash(N, 1);
00273   }
00274 };
00275 
00276 template <> struct MDNodeKeyImpl<MDSubrange> {
00277   int64_t Count;
00278   int64_t LowerBound;
00279 
00280   MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
00281       : Count(Count), LowerBound(LowerBound) {}
00282   MDNodeKeyImpl(const MDSubrange *N)
00283       : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
00284 
00285   bool isKeyOf(const MDSubrange *RHS) const {
00286     return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
00287   }
00288   unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
00289 };
00290 
00291 template <> struct MDNodeKeyImpl<MDEnumerator> {
00292   int64_t Value;
00293   StringRef Name;
00294 
00295   MDNodeKeyImpl(int64_t Value, StringRef Name) : Value(Value), Name(Name) {}
00296   MDNodeKeyImpl(const MDEnumerator *N)
00297       : Value(N->getValue()), Name(N->getName()) {}
00298 
00299   bool isKeyOf(const MDEnumerator *RHS) const {
00300     return Value == RHS->getValue() && Name == RHS->getName();
00301   }
00302   unsigned getHashValue() const { return hash_combine(Value, Name); }
00303 };
00304 
00305 template <> struct MDNodeKeyImpl<MDBasicType> {
00306   unsigned Tag;
00307   StringRef Name;
00308   uint64_t SizeInBits;
00309   uint64_t AlignInBits;
00310   unsigned Encoding;
00311 
00312   MDNodeKeyImpl(unsigned Tag, StringRef Name, uint64_t SizeInBits,
00313                 uint64_t AlignInBits, unsigned Encoding)
00314       : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
00315         Encoding(Encoding) {}
00316   MDNodeKeyImpl(const MDBasicType *N)
00317       : Tag(N->getTag()), Name(N->getName()), SizeInBits(N->getSizeInBits()),
00318         AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
00319 
00320   bool isKeyOf(const MDBasicType *RHS) const {
00321     return Tag == RHS->getTag() && Name == RHS->getName() &&
00322            SizeInBits == RHS->getSizeInBits() &&
00323            AlignInBits == RHS->getAlignInBits() &&
00324            Encoding == RHS->getEncoding();
00325   }
00326   unsigned getHashValue() const {
00327     return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
00328   }
00329 };
00330 
00331 template <> struct MDNodeKeyImpl<MDDerivedType> {
00332   unsigned Tag;
00333   StringRef Name;
00334   Metadata *File;
00335   unsigned Line;
00336   Metadata *Scope;
00337   Metadata *BaseType;
00338   uint64_t SizeInBits;
00339   uint64_t AlignInBits;
00340   uint64_t OffsetInBits;
00341   unsigned Flags;
00342   Metadata *ExtraData;
00343 
00344   MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *File, unsigned Line,
00345                 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
00346                 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
00347                 Metadata *ExtraData)
00348       : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
00349         BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
00350         OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {}
00351   MDNodeKeyImpl(const MDDerivedType *N)
00352       : Tag(N->getTag()), Name(N->getName()), File(N->getRawFile()),
00353         Line(N->getLine()), Scope(N->getRawScope()),
00354         BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
00355         AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
00356         Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {}
00357 
00358   bool isKeyOf(const MDDerivedType *RHS) const {
00359     return Tag == RHS->getTag() && Name == RHS->getName() &&
00360            File == RHS->getRawFile() && Line == RHS->getLine() &&
00361            Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
00362            SizeInBits == RHS->getSizeInBits() &&
00363            AlignInBits == RHS->getAlignInBits() &&
00364            OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
00365            ExtraData == RHS->getRawExtraData();
00366   }
00367   unsigned getHashValue() const {
00368     return hash_combine(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
00369                         AlignInBits, OffsetInBits, Flags, ExtraData);
00370   }
00371 };
00372 
00373 template <> struct MDNodeKeyImpl<MDCompositeType> {
00374   unsigned Tag;
00375   StringRef Name;
00376   Metadata *File;
00377   unsigned Line;
00378   Metadata *Scope;
00379   Metadata *BaseType;
00380   uint64_t SizeInBits;
00381   uint64_t AlignInBits;
00382   uint64_t OffsetInBits;
00383   unsigned Flags;
00384   Metadata *Elements;
00385   unsigned RuntimeLang;
00386   Metadata *VTableHolder;
00387   Metadata *TemplateParams;
00388   StringRef Identifier;
00389 
00390   MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *File, unsigned Line,
00391                 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
00392                 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
00393                 Metadata *Elements, unsigned RuntimeLang,
00394                 Metadata *VTableHolder, Metadata *TemplateParams,
00395                 StringRef Identifier)
00396       : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
00397         BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
00398         OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
00399         RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
00400         TemplateParams(TemplateParams), Identifier(Identifier) {}
00401   MDNodeKeyImpl(const MDCompositeType *N)
00402       : Tag(N->getTag()), Name(N->getName()), File(N->getRawFile()),
00403         Line(N->getLine()), Scope(N->getRawScope()),
00404         BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
00405         AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
00406         Flags(N->getFlags()), Elements(N->getRawElements()),
00407         RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
00408         TemplateParams(N->getRawTemplateParams()),
00409         Identifier(N->getIdentifier()) {}
00410 
00411   bool isKeyOf(const MDCompositeType *RHS) const {
00412     return Tag == RHS->getTag() && Name == RHS->getName() &&
00413            File == RHS->getRawFile() && Line == RHS->getLine() &&
00414            Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
00415            SizeInBits == RHS->getSizeInBits() &&
00416            AlignInBits == RHS->getAlignInBits() &&
00417            OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
00418            Elements == RHS->getRawElements() &&
00419            RuntimeLang == RHS->getRuntimeLang() &&
00420            VTableHolder == RHS->getRawVTableHolder() &&
00421            TemplateParams == RHS->getRawTemplateParams() &&
00422            Identifier == RHS->getIdentifier();
00423   }
00424   unsigned getHashValue() const {
00425     return hash_combine(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
00426                         AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
00427                         VTableHolder, TemplateParams, Identifier);
00428   }
00429 };
00430 
00431 template <> struct MDNodeKeyImpl<MDSubroutineType> {
00432   unsigned Flags;
00433   Metadata *TypeArray;
00434 
00435   MDNodeKeyImpl(int64_t Flags, Metadata *TypeArray)
00436       : Flags(Flags), TypeArray(TypeArray) {}
00437   MDNodeKeyImpl(const MDSubroutineType *N)
00438       : Flags(N->getFlags()), TypeArray(N->getRawTypeArray()) {}
00439 
00440   bool isKeyOf(const MDSubroutineType *RHS) const {
00441     return Flags == RHS->getFlags() && TypeArray == RHS->getRawTypeArray();
00442   }
00443   unsigned getHashValue() const { return hash_combine(Flags, TypeArray); }
00444 };
00445 
00446 template <> struct MDNodeKeyImpl<MDFile> {
00447   StringRef Filename;
00448   StringRef Directory;
00449 
00450   MDNodeKeyImpl(StringRef Filename, StringRef Directory)
00451       : Filename(Filename), Directory(Directory) {}
00452   MDNodeKeyImpl(const MDFile *N)
00453       : Filename(N->getFilename()), Directory(N->getDirectory()) {}
00454 
00455   bool isKeyOf(const MDFile *RHS) const {
00456     return Filename == RHS->getFilename() && Directory == RHS->getDirectory();
00457   }
00458   unsigned getHashValue() const { return hash_combine(Filename, Directory); }
00459 };
00460 
00461 template <> struct MDNodeKeyImpl<MDCompileUnit> {
00462   unsigned SourceLanguage;
00463   Metadata *File;
00464   StringRef Producer;
00465   bool IsOptimized;
00466   StringRef Flags;
00467   unsigned RuntimeVersion;
00468   StringRef SplitDebugFilename;
00469   unsigned EmissionKind;
00470   Metadata *EnumTypes;
00471   Metadata *RetainedTypes;
00472   Metadata *Subprograms;
00473   Metadata *GlobalVariables;
00474   Metadata *ImportedEntities;
00475 
00476   MDNodeKeyImpl(unsigned SourceLanguage, Metadata *File, StringRef Producer,
00477                 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
00478                 StringRef SplitDebugFilename, unsigned EmissionKind,
00479                 Metadata *EnumTypes, Metadata *RetainedTypes,
00480                 Metadata *Subprograms, Metadata *GlobalVariables,
00481                 Metadata *ImportedEntities)
00482       : SourceLanguage(SourceLanguage), File(File), Producer(Producer),
00483         IsOptimized(IsOptimized), Flags(Flags), RuntimeVersion(RuntimeVersion),
00484         SplitDebugFilename(SplitDebugFilename), EmissionKind(EmissionKind),
00485         EnumTypes(EnumTypes), RetainedTypes(RetainedTypes),
00486         Subprograms(Subprograms), GlobalVariables(GlobalVariables),
00487         ImportedEntities(ImportedEntities) {}
00488   MDNodeKeyImpl(const MDCompileUnit *N)
00489       : SourceLanguage(N->getSourceLanguage()), File(N->getRawFile()),
00490         Producer(N->getProducer()), IsOptimized(N->isOptimized()),
00491         Flags(N->getFlags()), RuntimeVersion(N->getRuntimeVersion()),
00492         SplitDebugFilename(N->getSplitDebugFilename()),
00493         EmissionKind(N->getEmissionKind()), EnumTypes(N->getRawEnumTypes()),
00494         RetainedTypes(N->getRawRetainedTypes()),
00495         Subprograms(N->getRawSubprograms()),
00496         GlobalVariables(N->getRawGlobalVariables()),
00497         ImportedEntities(N->getRawImportedEntities()) {}
00498 
00499   bool isKeyOf(const MDCompileUnit *RHS) const {
00500     return SourceLanguage == RHS->getSourceLanguage() &&
00501            File == RHS->getRawFile() && Producer == RHS->getProducer() &&
00502            IsOptimized == RHS->isOptimized() && Flags == RHS->getFlags() &&
00503            RuntimeVersion == RHS->getRuntimeVersion() &&
00504            SplitDebugFilename == RHS->getSplitDebugFilename() &&
00505            EmissionKind == RHS->getEmissionKind() &&
00506            EnumTypes == RHS->getRawEnumTypes() &&
00507            RetainedTypes == RHS->getRawRetainedTypes() &&
00508            Subprograms == RHS->getRawSubprograms() &&
00509            GlobalVariables == RHS->getRawGlobalVariables() &&
00510            ImportedEntities == RHS->getRawImportedEntities();
00511   }
00512   unsigned getHashValue() const {
00513     return hash_combine(SourceLanguage, File, Producer, IsOptimized, Flags,
00514                         RuntimeVersion, SplitDebugFilename, EmissionKind,
00515                         EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
00516                         ImportedEntities);
00517   }
00518 };
00519 
00520 template <> struct MDNodeKeyImpl<MDSubprogram> {
00521   Metadata *Scope;
00522   StringRef Name;
00523   StringRef LinkageName;
00524   Metadata *File;
00525   unsigned Line;
00526   Metadata *Type;
00527   bool IsLocalToUnit;
00528   bool IsDefinition;
00529   unsigned ScopeLine;
00530   Metadata *ContainingType;
00531   unsigned Virtuality;
00532   unsigned VirtualIndex;
00533   unsigned Flags;
00534   bool IsOptimized;
00535   Metadata *Function;
00536   Metadata *TemplateParams;
00537   Metadata *Declaration;
00538   Metadata *Variables;
00539 
00540   MDNodeKeyImpl(Metadata *Scope, StringRef Name, StringRef LinkageName,
00541                 Metadata *File, unsigned Line, Metadata *Type,
00542                 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
00543                 Metadata *ContainingType, unsigned Virtuality,
00544                 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
00545                 Metadata *Function, Metadata *TemplateParams,
00546                 Metadata *Declaration, Metadata *Variables)
00547       : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
00548         Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
00549         IsDefinition(IsDefinition), ScopeLine(ScopeLine),
00550         ContainingType(ContainingType), Virtuality(Virtuality),
00551         VirtualIndex(VirtualIndex), Flags(Flags), IsOptimized(IsOptimized),
00552         Function(Function), TemplateParams(TemplateParams),
00553         Declaration(Declaration), Variables(Variables) {}
00554   MDNodeKeyImpl(const MDSubprogram *N)
00555       : Scope(N->getRawScope()), Name(N->getName()),
00556         LinkageName(N->getLinkageName()), File(N->getRawFile()),
00557         Line(N->getLine()), Type(N->getRawType()),
00558         IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
00559         ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
00560         Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
00561         Flags(N->getFlags()), IsOptimized(N->isOptimized()),
00562         Function(N->getRawFunction()),
00563         TemplateParams(N->getRawTemplateParams()),
00564         Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
00565 
00566   bool isKeyOf(const MDSubprogram *RHS) const {
00567     return Scope == RHS->getRawScope() && Name == RHS->getName() &&
00568            LinkageName == RHS->getLinkageName() && File == RHS->getRawFile() &&
00569            Line == RHS->getLine() && Type == RHS->getRawType() &&
00570            IsLocalToUnit == RHS->isLocalToUnit() &&
00571            IsDefinition == RHS->isDefinition() &&
00572            ScopeLine == RHS->getScopeLine() &&
00573            ContainingType == RHS->getRawContainingType() &&
00574            Virtuality == RHS->getVirtuality() &&
00575            VirtualIndex == RHS->getVirtualIndex() && Flags == RHS->getFlags() &&
00576            IsOptimized == RHS->isOptimized() &&
00577            Function == RHS->getRawFunction() &&
00578            TemplateParams == RHS->getRawTemplateParams() &&
00579            Declaration == RHS->getRawDeclaration() &&
00580            Variables == RHS->getRawVariables();
00581   }
00582   unsigned getHashValue() const {
00583     return hash_combine(Scope, Name, LinkageName, File, Line, Type,
00584                         IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
00585                         Virtuality, VirtualIndex, Flags, IsOptimized, Function,
00586                         TemplateParams, Declaration, Variables);
00587   }
00588 };
00589 
00590 template <> struct MDNodeKeyImpl<MDLexicalBlock> {
00591   Metadata *Scope;
00592   Metadata *File;
00593   unsigned Line;
00594   unsigned Column;
00595 
00596   MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
00597       : Scope(Scope), File(File), Line(Line), Column(Column) {}
00598   MDNodeKeyImpl(const MDLexicalBlock *N)
00599       : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
00600         Column(N->getColumn()) {}
00601 
00602   bool isKeyOf(const MDLexicalBlock *RHS) const {
00603     return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
00604            Line == RHS->getLine() && Column == RHS->getColumn();
00605   }
00606   unsigned getHashValue() const {
00607     return hash_combine(Scope, File, Line, Column);
00608   }
00609 };
00610 
00611 template <> struct MDNodeKeyImpl<MDLexicalBlockFile> {
00612   Metadata *Scope;
00613   Metadata *File;
00614   unsigned Discriminator;
00615 
00616   MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
00617       : Scope(Scope), File(File), Discriminator(Discriminator) {}
00618   MDNodeKeyImpl(const MDLexicalBlockFile *N)
00619       : Scope(N->getRawScope()), File(N->getRawFile()),
00620         Discriminator(N->getDiscriminator()) {}
00621 
00622   bool isKeyOf(const MDLexicalBlockFile *RHS) const {
00623     return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
00624            Discriminator == RHS->getDiscriminator();
00625   }
00626   unsigned getHashValue() const {
00627     return hash_combine(Scope, File, Discriminator);
00628   }
00629 };
00630 
00631 template <> struct MDNodeKeyImpl<MDNamespace> {
00632   Metadata *Scope;
00633   Metadata *File;
00634   StringRef Name;
00635   unsigned Line;
00636 
00637   MDNodeKeyImpl(Metadata *Scope, Metadata *File, StringRef Name, unsigned Line)
00638       : Scope(Scope), File(File), Name(Name), Line(Line) {}
00639   MDNodeKeyImpl(const MDNamespace *N)
00640       : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getName()),
00641         Line(N->getLine()) {}
00642 
00643   bool isKeyOf(const MDNamespace *RHS) const {
00644     return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
00645            Name == RHS->getName() && Line == RHS->getLine();
00646   }
00647   unsigned getHashValue() const {
00648     return hash_combine(Scope, File, Name, Line);
00649   }
00650 };
00651 
00652 template <> struct MDNodeKeyImpl<MDTemplateTypeParameter> {
00653   StringRef Name;
00654   Metadata *Type;
00655 
00656   MDNodeKeyImpl(StringRef Name, Metadata *Type) : Name(Name), Type(Type) {}
00657   MDNodeKeyImpl(const MDTemplateTypeParameter *N)
00658       : Name(N->getName()), Type(N->getRawType()) {}
00659 
00660   bool isKeyOf(const MDTemplateTypeParameter *RHS) const {
00661     return Name == RHS->getName() && Type == RHS->getRawType();
00662   }
00663   unsigned getHashValue() const { return hash_combine(Name, Type); }
00664 };
00665 
00666 template <> struct MDNodeKeyImpl<MDTemplateValueParameter> {
00667   unsigned Tag;
00668   StringRef Name;
00669   Metadata *Type;
00670   Metadata *Value;
00671 
00672   MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *Type, Metadata *Value)
00673       : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
00674   MDNodeKeyImpl(const MDTemplateValueParameter *N)
00675       : Tag(N->getTag()), Name(N->getName()), Type(N->getRawType()),
00676         Value(N->getValue()) {}
00677 
00678   bool isKeyOf(const MDTemplateValueParameter *RHS) const {
00679     return Tag == RHS->getTag() && Name == RHS->getName() &&
00680            Type == RHS->getRawType() && Value == RHS->getValue();
00681   }
00682   unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
00683 };
00684 
00685 template <> struct MDNodeKeyImpl<MDGlobalVariable> {
00686   Metadata *Scope;
00687   StringRef Name;
00688   StringRef LinkageName;
00689   Metadata *File;
00690   unsigned Line;
00691   Metadata *Type;
00692   bool IsLocalToUnit;
00693   bool IsDefinition;
00694   Metadata *Variable;
00695   Metadata *StaticDataMemberDeclaration;
00696 
00697   MDNodeKeyImpl(Metadata *Scope, StringRef Name, StringRef LinkageName,
00698                 Metadata *File, unsigned Line, Metadata *Type,
00699                 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
00700                 Metadata *StaticDataMemberDeclaration)
00701       : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
00702         Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
00703         IsDefinition(IsDefinition), Variable(Variable),
00704         StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
00705   MDNodeKeyImpl(const MDGlobalVariable *N)
00706       : Scope(N->getRawScope()), Name(N->getName()),
00707         LinkageName(N->getLinkageName()), File(N->getRawFile()),
00708         Line(N->getLine()), Type(N->getRawType()),
00709         IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
00710         Variable(N->getRawVariable()),
00711         StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
00712 
00713   bool isKeyOf(const MDGlobalVariable *RHS) const {
00714     return Scope == RHS->getRawScope() && Name == RHS->getName() &&
00715            LinkageName == RHS->getLinkageName() && File == RHS->getRawFile() &&
00716            Line == RHS->getLine() && Type == RHS->getRawType() &&
00717            IsLocalToUnit == RHS->isLocalToUnit() &&
00718            IsDefinition == RHS->isDefinition() &&
00719            Variable == RHS->getRawVariable() &&
00720            StaticDataMemberDeclaration ==
00721                RHS->getRawStaticDataMemberDeclaration();
00722   }
00723   unsigned getHashValue() const {
00724     return hash_combine(Scope, Name, LinkageName, File, Line, Type,
00725                         IsLocalToUnit, IsDefinition, Variable,
00726                         StaticDataMemberDeclaration);
00727   }
00728 };
00729 
00730 template <> struct MDNodeKeyImpl<MDLocalVariable> {
00731   unsigned Tag;
00732   Metadata *Scope;
00733   StringRef Name;
00734   Metadata *File;
00735   unsigned Line;
00736   Metadata *Type;
00737   unsigned Arg;
00738   unsigned Flags;
00739 
00740   MDNodeKeyImpl(unsigned Tag, Metadata *Scope, StringRef Name, Metadata *File,
00741                 unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags)
00742       : Tag(Tag), Scope(Scope), Name(Name), File(File), Line(Line), Type(Type),
00743         Arg(Arg), Flags(Flags) {}
00744   MDNodeKeyImpl(const MDLocalVariable *N)
00745       : Tag(N->getTag()), Scope(N->getRawScope()), Name(N->getName()),
00746         File(N->getRawFile()), Line(N->getLine()), Type(N->getRawType()),
00747         Arg(N->getArg()), Flags(N->getFlags()) {}
00748 
00749   bool isKeyOf(const MDLocalVariable *RHS) const {
00750     return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
00751            Name == RHS->getName() && File == RHS->getRawFile() &&
00752            Line == RHS->getLine() && Type == RHS->getRawType() &&
00753            Arg == RHS->getArg() && Flags == RHS->getFlags();
00754   }
00755   unsigned getHashValue() const {
00756     return hash_combine(Tag, Scope, Name, File, Line, Type, Arg, Flags);
00757   }
00758 };
00759 
00760 template <> struct MDNodeKeyImpl<MDExpression> {
00761   ArrayRef<uint64_t> Elements;
00762 
00763   MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
00764   MDNodeKeyImpl(const MDExpression *N) : Elements(N->getElements()) {}
00765 
00766   bool isKeyOf(const MDExpression *RHS) const {
00767     return Elements == RHS->getElements();
00768   }
00769   unsigned getHashValue() const {
00770     return hash_combine_range(Elements.begin(), Elements.end());
00771   }
00772 };
00773 
00774 template <> struct MDNodeKeyImpl<MDObjCProperty> {
00775   StringRef Name;
00776   Metadata *File;
00777   unsigned Line;
00778   StringRef GetterName;
00779   StringRef SetterName;
00780   unsigned Attributes;
00781   Metadata *Type;
00782 
00783   MDNodeKeyImpl(StringRef Name, Metadata *File, unsigned Line,
00784                 StringRef GetterName, StringRef SetterName, unsigned Attributes,
00785                 Metadata *Type)
00786       : Name(Name), File(File), Line(Line), GetterName(GetterName),
00787         SetterName(SetterName), Attributes(Attributes), Type(Type) {}
00788   MDNodeKeyImpl(const MDObjCProperty *N)
00789       : Name(N->getName()), File(N->getRawFile()), Line(N->getLine()),
00790         GetterName(N->getGetterName()), SetterName(N->getSetterName()),
00791         Attributes(N->getAttributes()), Type(N->getRawType()) {}
00792 
00793   bool isKeyOf(const MDObjCProperty *RHS) const {
00794     return Name == RHS->getName() && File == RHS->getRawFile() &&
00795            Line == RHS->getLine() && GetterName == RHS->getGetterName() &&
00796            SetterName == RHS->getSetterName() &&
00797            Attributes == RHS->getAttributes() && Type == RHS->getRawType();
00798   }
00799   unsigned getHashValue() const {
00800     return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
00801                         Type);
00802   }
00803 };
00804 
00805 template <> struct MDNodeKeyImpl<MDImportedEntity> {
00806   unsigned Tag;
00807   Metadata *Scope;
00808   Metadata *Entity;
00809   unsigned Line;
00810   StringRef Name;
00811 
00812   MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
00813                 StringRef Name)
00814       : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
00815   MDNodeKeyImpl(const MDImportedEntity *N)
00816       : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
00817         Line(N->getLine()), Name(N->getName()) {}
00818 
00819   bool isKeyOf(const MDImportedEntity *RHS) const {
00820     return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
00821            Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
00822            Name == RHS->getName();
00823   }
00824   unsigned getHashValue() const {
00825     return hash_combine(Tag, Scope, Entity, Line, Name);
00826   }
00827 };
00828 
00829 /// \brief DenseMapInfo for MDNode subclasses.
00830 template <class NodeTy> struct MDNodeInfo {
00831   typedef MDNodeKeyImpl<NodeTy> KeyTy;
00832   static inline NodeTy *getEmptyKey() {
00833     return DenseMapInfo<NodeTy *>::getEmptyKey();
00834   }
00835   static inline NodeTy *getTombstoneKey() {
00836     return DenseMapInfo<NodeTy *>::getTombstoneKey();
00837   }
00838   static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
00839   static unsigned getHashValue(const NodeTy *N) {
00840     return KeyTy(N).getHashValue();
00841   }
00842   static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
00843     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
00844       return false;
00845     return LHS.isKeyOf(RHS);
00846   }
00847   static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
00848     return LHS == RHS;
00849   }
00850 };
00851 
00852 #define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
00853 #include "llvm/IR/Metadata.def"
00854 
00855 class LLVMContextImpl {
00856 public:
00857   /// OwnedModules - The set of modules instantiated in this context, and which
00858   /// will be automatically deleted if this context is deleted.
00859   SmallPtrSet<Module*, 4> OwnedModules;
00860   
00861   LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
00862   void *InlineAsmDiagContext;
00863 
00864   LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
00865   void *DiagnosticContext;
00866   bool RespectDiagnosticFilters;
00867 
00868   LLVMContext::YieldCallbackTy YieldCallback;
00869   void *YieldOpaqueHandle;
00870 
00871   typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
00872   IntMapTy IntConstants;
00873 
00874   typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
00875   FPMapTy FPConstants;
00876 
00877   FoldingSet<AttributeImpl> AttrsSet;
00878   FoldingSet<AttributeSetImpl> AttrsLists;
00879   FoldingSet<AttributeSetNode> AttrsSetNodes;
00880 
00881   StringMap<MDString> MDStringCache;
00882   DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
00883   DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
00884 
00885 #define HANDLE_MDNODE_LEAF(CLASS) DenseSet<CLASS *, CLASS##Info> CLASS##s;
00886 #include "llvm/IR/Metadata.def"
00887 
00888   // MDNodes may be uniqued or not uniqued.  When they're not uniqued, they
00889   // aren't in the MDNodeSet, but they're still shared between objects, so no
00890   // one object can destroy them.  This set allows us to at least destroy them
00891   // on Context destruction.
00892   SmallPtrSet<MDNode *, 1> DistinctMDNodes;
00893 
00894   DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
00895 
00896   typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
00897   ArrayConstantsTy ArrayConstants;
00898   
00899   typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
00900   StructConstantsTy StructConstants;
00901   
00902   typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
00903   VectorConstantsTy VectorConstants;
00904   
00905   DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
00906 
00907   DenseMap<Type*, UndefValue*> UVConstants;
00908   
00909   StringMap<ConstantDataSequential*> CDSConstants;
00910 
00911   DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
00912     BlockAddresses;
00913   ConstantUniqueMap<ConstantExpr> ExprConstants;
00914 
00915   ConstantUniqueMap<InlineAsm> InlineAsms;
00916 
00917   ConstantInt *TheTrueVal;
00918   ConstantInt *TheFalseVal;
00919 
00920   // Basic type instances.
00921   Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy;
00922   Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
00923   IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
00924 
00925   
00926   /// TypeAllocator - All dynamically allocated types are allocated from this.
00927   /// They live forever until the context is torn down.
00928   BumpPtrAllocator TypeAllocator;
00929   
00930   DenseMap<unsigned, IntegerType*> IntegerTypes;
00931 
00932   typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
00933   FunctionTypeSet FunctionTypes;
00934   typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
00935   StructTypeSet AnonStructTypes;
00936   StringMap<StructType*> NamedStructTypes;
00937   unsigned NamedStructTypesUniqueID;
00938     
00939   DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
00940   DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
00941   DenseMap<Type*, PointerType*> PointerTypes;  // Pointers in AddrSpace = 0
00942   DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
00943 
00944 
00945   /// ValueHandles - This map keeps track of all of the value handles that are
00946   /// watching a Value*.  The Value::HasValueHandle bit is used to know
00947   /// whether or not a value has an entry in this map.
00948   typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
00949   ValueHandlesTy ValueHandles;
00950   
00951   /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
00952   StringMap<unsigned> CustomMDKindNames;
00953 
00954   typedef std::pair<unsigned, TrackingMDNodeRef> MDPairTy;
00955   typedef SmallVector<MDPairTy, 2> MDMapTy;
00956 
00957   /// MetadataStore - Collection of per-instruction metadata used in this
00958   /// context.
00959   DenseMap<const Instruction *, MDMapTy> MetadataStore;
00960   
00961   /// DiscriminatorTable - This table maps file:line locations to an
00962   /// integer representing the next DWARF path discriminator to assign to
00963   /// instructions in different blocks at the same location.
00964   DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
00965 
00966   /// IntrinsicIDCache - Cache of intrinsic name (string) to numeric ID mappings
00967   /// requested in this context
00968   typedef DenseMap<const Function*, unsigned> IntrinsicIDCacheTy;
00969   IntrinsicIDCacheTy IntrinsicIDCache;
00970 
00971   /// \brief Mapping from a function to its prefix data, which is stored as the
00972   /// operand of an unparented ReturnInst so that the prefix data has a Use.
00973   typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
00974   PrefixDataMapTy PrefixDataMap;
00975 
00976   /// \brief Mapping from a function to its prologue data, which is stored as
00977   /// the operand of an unparented ReturnInst so that the prologue data has a
00978   /// Use.
00979   typedef DenseMap<const Function *, ReturnInst *> PrologueDataMapTy;
00980   PrologueDataMapTy PrologueDataMap;
00981 
00982   int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
00983   int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
00984 
00985   LLVMContextImpl(LLVMContext &C);
00986   ~LLVMContextImpl();
00987 
00988   /// Destroy the ConstantArrays if they are not used.
00989   void dropTriviallyDeadConstantArrays();
00990 };
00991 
00992 }
00993 
00994 #endif