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 Lo;
00279 
00280   MDNodeKeyImpl(int64_t Count, int64_t Lo) : Count(Count), Lo(Lo) {}
00281   MDNodeKeyImpl(const MDSubrange *N) : Count(N->getCount()), Lo(N->getLo()) {}
00282 
00283   bool isKeyOf(const MDSubrange *RHS) const {
00284     return Count == RHS->getCount() && Lo == RHS->getLo();
00285   }
00286   unsigned getHashValue() const { return hash_combine(Count, Lo); }
00287 };
00288 
00289 template <> struct MDNodeKeyImpl<MDEnumerator> {
00290   int64_t Value;
00291   StringRef Name;
00292 
00293   MDNodeKeyImpl(int64_t Value, StringRef Name) : Value(Value), Name(Name) {}
00294   MDNodeKeyImpl(const MDEnumerator *N)
00295       : Value(N->getValue()), Name(N->getName()) {}
00296 
00297   bool isKeyOf(const MDEnumerator *RHS) const {
00298     return Value == RHS->getValue() && Name == RHS->getName();
00299   }
00300   unsigned getHashValue() const { return hash_combine(Value, Name); }
00301 };
00302 
00303 template <> struct MDNodeKeyImpl<MDBasicType> {
00304   unsigned Tag;
00305   StringRef Name;
00306   uint64_t SizeInBits;
00307   uint64_t AlignInBits;
00308   unsigned Encoding;
00309 
00310   MDNodeKeyImpl(unsigned Tag, StringRef Name, uint64_t SizeInBits,
00311                 uint64_t AlignInBits, unsigned Encoding)
00312       : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
00313         Encoding(Encoding) {}
00314   MDNodeKeyImpl(const MDBasicType *N)
00315       : Tag(N->getTag()), Name(N->getName()), SizeInBits(N->getSizeInBits()),
00316         AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
00317 
00318   bool isKeyOf(const MDBasicType *RHS) const {
00319     return Tag == RHS->getTag() && Name == RHS->getName() &&
00320            SizeInBits == RHS->getSizeInBits() &&
00321            AlignInBits == RHS->getAlignInBits() &&
00322            Encoding == RHS->getEncoding();
00323   }
00324   unsigned getHashValue() const {
00325     return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
00326   }
00327 };
00328 
00329 template <> struct MDNodeKeyImpl<MDDerivedType> {
00330   unsigned Tag;
00331   StringRef Name;
00332   Metadata *File;
00333   unsigned Line;
00334   Metadata *Scope;
00335   Metadata *BaseType;
00336   uint64_t SizeInBits;
00337   uint64_t AlignInBits;
00338   uint64_t OffsetInBits;
00339   unsigned Flags;
00340   Metadata *ExtraData;
00341 
00342   MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *File, unsigned Line,
00343                 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
00344                 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
00345                 Metadata *ExtraData)
00346       : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
00347         BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
00348         OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {}
00349   MDNodeKeyImpl(const MDDerivedType *N)
00350       : Tag(N->getTag()), Name(N->getName()), File(N->getRawFile()),
00351         Line(N->getLine()), Scope(N->getRawScope()),
00352         BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
00353         AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
00354         Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {}
00355 
00356   bool isKeyOf(const MDDerivedType *RHS) const {
00357     return Tag == RHS->getTag() && Name == RHS->getName() &&
00358            File == RHS->getRawFile() && Line == RHS->getLine() &&
00359            Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
00360            SizeInBits == RHS->getSizeInBits() &&
00361            AlignInBits == RHS->getAlignInBits() &&
00362            OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
00363            ExtraData == RHS->getRawExtraData();
00364   }
00365   unsigned getHashValue() const {
00366     return hash_combine(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
00367                         AlignInBits, OffsetInBits, Flags, ExtraData);
00368   }
00369 };
00370 
00371 template <> struct MDNodeKeyImpl<MDCompositeType> {
00372   unsigned Tag;
00373   StringRef Name;
00374   Metadata *File;
00375   unsigned Line;
00376   Metadata *Scope;
00377   Metadata *BaseType;
00378   uint64_t SizeInBits;
00379   uint64_t AlignInBits;
00380   uint64_t OffsetInBits;
00381   unsigned Flags;
00382   Metadata *Elements;
00383   unsigned RuntimeLang;
00384   Metadata *VTableHolder;
00385   Metadata *TemplateParams;
00386   StringRef Identifier;
00387 
00388   MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *File, unsigned Line,
00389                 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
00390                 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
00391                 Metadata *Elements, unsigned RuntimeLang,
00392                 Metadata *VTableHolder, Metadata *TemplateParams,
00393                 StringRef Identifier)
00394       : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
00395         BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
00396         OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
00397         RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
00398         TemplateParams(TemplateParams), Identifier(Identifier) {}
00399   MDNodeKeyImpl(const MDCompositeType *N)
00400       : Tag(N->getTag()), Name(N->getName()), File(N->getRawFile()),
00401         Line(N->getLine()), Scope(N->getRawScope()),
00402         BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
00403         AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
00404         Flags(N->getFlags()), Elements(N->getRawElements()),
00405         RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
00406         TemplateParams(N->getRawTemplateParams()),
00407         Identifier(N->getIdentifier()) {}
00408 
00409   bool isKeyOf(const MDCompositeType *RHS) const {
00410     return Tag == RHS->getTag() && Name == RHS->getName() &&
00411            File == RHS->getRawFile() && Line == RHS->getLine() &&
00412            Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
00413            SizeInBits == RHS->getSizeInBits() &&
00414            AlignInBits == RHS->getAlignInBits() &&
00415            OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
00416            Elements == RHS->getRawElements() &&
00417            RuntimeLang == RHS->getRuntimeLang() &&
00418            VTableHolder == RHS->getRawVTableHolder() &&
00419            TemplateParams == RHS->getRawTemplateParams() &&
00420            Identifier == RHS->getIdentifier();
00421   }
00422   unsigned getHashValue() const {
00423     return hash_combine(Tag, Name, File, Line, Scope, BaseType, SizeInBits,
00424                         AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
00425                         VTableHolder, TemplateParams, Identifier);
00426   }
00427 };
00428 
00429 template <> struct MDNodeKeyImpl<MDSubroutineType> {
00430   unsigned Flags;
00431   Metadata *TypeArray;
00432 
00433   MDNodeKeyImpl(int64_t Flags, Metadata *TypeArray)
00434       : Flags(Flags), TypeArray(TypeArray) {}
00435   MDNodeKeyImpl(const MDSubroutineType *N)
00436       : Flags(N->getFlags()), TypeArray(N->getRawTypeArray()) {}
00437 
00438   bool isKeyOf(const MDSubroutineType *RHS) const {
00439     return Flags == RHS->getFlags() && TypeArray == RHS->getRawTypeArray();
00440   }
00441   unsigned getHashValue() const { return hash_combine(Flags, TypeArray); }
00442 };
00443 
00444 template <> struct MDNodeKeyImpl<MDFile> {
00445   StringRef Filename;
00446   StringRef Directory;
00447 
00448   MDNodeKeyImpl(StringRef Filename, StringRef Directory)
00449       : Filename(Filename), Directory(Directory) {}
00450   MDNodeKeyImpl(const MDFile *N)
00451       : Filename(N->getFilename()), Directory(N->getDirectory()) {}
00452 
00453   bool isKeyOf(const MDFile *RHS) const {
00454     return Filename == RHS->getFilename() && Directory == RHS->getDirectory();
00455   }
00456   unsigned getHashValue() const { return hash_combine(Filename, Directory); }
00457 };
00458 
00459 template <> struct MDNodeKeyImpl<MDCompileUnit> {
00460   unsigned SourceLanguage;
00461   Metadata *File;
00462   StringRef Producer;
00463   bool IsOptimized;
00464   StringRef Flags;
00465   unsigned RuntimeVersion;
00466   StringRef SplitDebugFilename;
00467   unsigned EmissionKind;
00468   Metadata *EnumTypes;
00469   Metadata *RetainedTypes;
00470   Metadata *Subprograms;
00471   Metadata *GlobalVariables;
00472   Metadata *ImportedEntities;
00473 
00474   MDNodeKeyImpl(unsigned SourceLanguage, Metadata *File, StringRef Producer,
00475                 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
00476                 StringRef SplitDebugFilename, unsigned EmissionKind,
00477                 Metadata *EnumTypes, Metadata *RetainedTypes,
00478                 Metadata *Subprograms, Metadata *GlobalVariables,
00479                 Metadata *ImportedEntities)
00480       : SourceLanguage(SourceLanguage), File(File), Producer(Producer),
00481         IsOptimized(IsOptimized), Flags(Flags), RuntimeVersion(RuntimeVersion),
00482         SplitDebugFilename(SplitDebugFilename), EmissionKind(EmissionKind),
00483         EnumTypes(EnumTypes), RetainedTypes(RetainedTypes),
00484         Subprograms(Subprograms), GlobalVariables(GlobalVariables),
00485         ImportedEntities(ImportedEntities) {}
00486   MDNodeKeyImpl(const MDCompileUnit *N)
00487       : SourceLanguage(N->getSourceLanguage()), File(N->getRawFile()),
00488         Producer(N->getProducer()), IsOptimized(N->isOptimized()),
00489         Flags(N->getFlags()), RuntimeVersion(N->getRuntimeVersion()),
00490         SplitDebugFilename(N->getSplitDebugFilename()),
00491         EmissionKind(N->getEmissionKind()), EnumTypes(N->getRawEnumTypes()),
00492         RetainedTypes(N->getRawRetainedTypes()),
00493         Subprograms(N->getRawSubprograms()),
00494         GlobalVariables(N->getRawGlobalVariables()),
00495         ImportedEntities(N->getRawImportedEntities()) {}
00496 
00497   bool isKeyOf(const MDCompileUnit *RHS) const {
00498     return SourceLanguage == RHS->getSourceLanguage() &&
00499            File == RHS->getRawFile() && Producer == RHS->getProducer() &&
00500            IsOptimized == RHS->isOptimized() && Flags == RHS->getFlags() &&
00501            RuntimeVersion == RHS->getRuntimeVersion() &&
00502            SplitDebugFilename == RHS->getSplitDebugFilename() &&
00503            EmissionKind == RHS->getEmissionKind() &&
00504            EnumTypes == RHS->getRawEnumTypes() &&
00505            RetainedTypes == RHS->getRawRetainedTypes() &&
00506            Subprograms == RHS->getRawSubprograms() &&
00507            GlobalVariables == RHS->getRawGlobalVariables() &&
00508            ImportedEntities == RHS->getRawImportedEntities();
00509   }
00510   unsigned getHashValue() const {
00511     return hash_combine(SourceLanguage, File, Producer, IsOptimized, Flags,
00512                         RuntimeVersion, SplitDebugFilename, EmissionKind,
00513                         EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
00514                         ImportedEntities);
00515   }
00516 };
00517 
00518 template <> struct MDNodeKeyImpl<MDSubprogram> {
00519   Metadata *Scope;
00520   StringRef Name;
00521   StringRef LinkageName;
00522   Metadata *File;
00523   unsigned Line;
00524   Metadata *Type;
00525   bool IsLocalToUnit;
00526   bool IsDefinition;
00527   unsigned ScopeLine;
00528   Metadata *ContainingType;
00529   unsigned Virtuality;
00530   unsigned VirtualIndex;
00531   unsigned Flags;
00532   bool IsOptimized;
00533   Metadata *Function;
00534   Metadata *TemplateParams;
00535   Metadata *Declaration;
00536   Metadata *Variables;
00537 
00538   MDNodeKeyImpl(Metadata *Scope, StringRef Name, StringRef LinkageName,
00539                 Metadata *File, unsigned Line, Metadata *Type,
00540                 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
00541                 Metadata *ContainingType, unsigned Virtuality,
00542                 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
00543                 Metadata *Function, Metadata *TemplateParams,
00544                 Metadata *Declaration, Metadata *Variables)
00545       : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
00546         Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
00547         IsDefinition(IsDefinition), ScopeLine(ScopeLine),
00548         ContainingType(ContainingType), Virtuality(Virtuality),
00549         VirtualIndex(VirtualIndex), Flags(Flags), IsOptimized(IsOptimized),
00550         Function(Function), TemplateParams(TemplateParams),
00551         Declaration(Declaration), Variables(Variables) {}
00552   MDNodeKeyImpl(const MDSubprogram *N)
00553       : Scope(N->getScope()), Name(N->getName()),
00554         LinkageName(N->getLinkageName()), File(N->getFile()),
00555         Line(N->getLine()), Type(N->getType()),
00556         IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
00557         ScopeLine(N->getScopeLine()), ContainingType(N->getContainingType()),
00558         Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
00559         Flags(N->getFlags()), IsOptimized(N->isOptimized()),
00560         Function(N->getFunction()), TemplateParams(N->getTemplateParams()),
00561         Declaration(N->getDeclaration()), Variables(N->getVariables()) {}
00562 
00563   bool isKeyOf(const MDSubprogram *RHS) const {
00564     return Scope == RHS->getScope() && Name == RHS->getName() &&
00565            LinkageName == RHS->getLinkageName() && File == RHS->getFile() &&
00566            Line == RHS->getLine() && Type == RHS->getType() &&
00567            IsLocalToUnit == RHS->isLocalToUnit() &&
00568            IsDefinition == RHS->isDefinition() &&
00569            ScopeLine == RHS->getScopeLine() &&
00570            ContainingType == RHS->getContainingType() &&
00571            Virtuality == RHS->getVirtuality() &&
00572            VirtualIndex == RHS->getVirtualIndex() && Flags == RHS->getFlags() &&
00573            IsOptimized == RHS->isOptimized() &&
00574            Function == RHS->getFunction() &&
00575            TemplateParams == RHS->getTemplateParams() &&
00576            Declaration == RHS->getDeclaration() &&
00577            Variables == RHS->getVariables();
00578   }
00579   unsigned getHashValue() const {
00580     return hash_combine(Scope, Name, LinkageName, File, Line, Type,
00581                         IsLocalToUnit, IsDefinition, ScopeLine, ContainingType,
00582                         Virtuality, VirtualIndex, Flags, IsOptimized, Function,
00583                         TemplateParams, Declaration, Variables);
00584   }
00585 };
00586 
00587 template <> struct MDNodeKeyImpl<MDLexicalBlock> {
00588   Metadata *Scope;
00589   Metadata *File;
00590   unsigned Line;
00591   unsigned Column;
00592 
00593   MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
00594       : Scope(Scope), File(File), Line(Line), Column(Column) {}
00595   MDNodeKeyImpl(const MDLexicalBlock *N)
00596       : Scope(N->getScope()), File(N->getFile()), Line(N->getLine()),
00597         Column(N->getColumn()) {}
00598 
00599   bool isKeyOf(const MDLexicalBlock *RHS) const {
00600     return Scope == RHS->getScope() && File == RHS->getFile() &&
00601            Line == RHS->getLine() && Column == RHS->getColumn();
00602   }
00603   unsigned getHashValue() const {
00604     return hash_combine(Scope, File, Line, Column);
00605   }
00606 };
00607 
00608 template <> struct MDNodeKeyImpl<MDLexicalBlockFile> {
00609   Metadata *Scope;
00610   Metadata *File;
00611   unsigned Discriminator;
00612 
00613   MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
00614       : Scope(Scope), File(File), Discriminator(Discriminator) {}
00615   MDNodeKeyImpl(const MDLexicalBlockFile *N)
00616       : Scope(N->getScope()), File(N->getFile()),
00617         Discriminator(N->getDiscriminator()) {}
00618 
00619   bool isKeyOf(const MDLexicalBlockFile *RHS) const {
00620     return Scope == RHS->getScope() && File == RHS->getFile() &&
00621            Discriminator == RHS->getDiscriminator();
00622   }
00623   unsigned getHashValue() const {
00624     return hash_combine(Scope, File, Discriminator);
00625   }
00626 };
00627 
00628 template <> struct MDNodeKeyImpl<MDNamespace> {
00629   Metadata *Scope;
00630   Metadata *File;
00631   StringRef Name;
00632   unsigned Line;
00633 
00634   MDNodeKeyImpl(Metadata *Scope, Metadata *File, StringRef Name, unsigned Line)
00635       : Scope(Scope), File(File), Name(Name), Line(Line) {}
00636   MDNodeKeyImpl(const MDNamespace *N)
00637       : Scope(N->getScope()), File(N->getFile()), Name(N->getName()),
00638         Line(N->getLine()) {}
00639 
00640   bool isKeyOf(const MDNamespace *RHS) const {
00641     return Scope == RHS->getScope() && File == RHS->getFile() &&
00642            Name == RHS->getName() && Line == RHS->getLine();
00643   }
00644   unsigned getHashValue() const {
00645     return hash_combine(Scope, File, Name, Line);
00646   }
00647 };
00648 
00649 template <> struct MDNodeKeyImpl<MDTemplateTypeParameter> {
00650   StringRef Name;
00651   Metadata *Type;
00652 
00653   MDNodeKeyImpl(StringRef Name, Metadata *Type) : Name(Name), Type(Type) {}
00654   MDNodeKeyImpl(const MDTemplateTypeParameter *N)
00655       : Name(N->getName()), Type(N->getType()) {}
00656 
00657   bool isKeyOf(const MDTemplateTypeParameter *RHS) const {
00658     return Name == RHS->getName() && Type == RHS->getType();
00659   }
00660   unsigned getHashValue() const { return hash_combine(Name, Type); }
00661 };
00662 
00663 template <> struct MDNodeKeyImpl<MDTemplateValueParameter> {
00664   unsigned Tag;
00665   StringRef Name;
00666   Metadata *Type;
00667   Metadata *Value;
00668 
00669   MDNodeKeyImpl(unsigned Tag, StringRef Name, Metadata *Type, Metadata *Value)
00670       : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
00671   MDNodeKeyImpl(const MDTemplateValueParameter *N)
00672       : Tag(N->getTag()), Name(N->getName()), Type(N->getType()),
00673         Value(N->getValue()) {}
00674 
00675   bool isKeyOf(const MDTemplateValueParameter *RHS) const {
00676     return Tag == RHS->getTag() && Name == RHS->getName() &&
00677            Type == RHS->getType() && Value == RHS->getValue();
00678   }
00679   unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
00680 };
00681 
00682 template <> struct MDNodeKeyImpl<MDGlobalVariable> {
00683   Metadata *Scope;
00684   StringRef Name;
00685   StringRef LinkageName;
00686   Metadata *File;
00687   unsigned Line;
00688   Metadata *Type;
00689   bool IsLocalToUnit;
00690   bool IsDefinition;
00691   Metadata *Variable;
00692   Metadata *StaticDataMemberDeclaration;
00693 
00694   MDNodeKeyImpl(Metadata *Scope, StringRef Name, StringRef LinkageName,
00695                 Metadata *File, unsigned Line, Metadata *Type,
00696                 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
00697                 Metadata *StaticDataMemberDeclaration)
00698       : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
00699         Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
00700         IsDefinition(IsDefinition), Variable(Variable),
00701         StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
00702   MDNodeKeyImpl(const MDGlobalVariable *N)
00703       : Scope(N->getRawScope()), Name(N->getName()),
00704         LinkageName(N->getLinkageName()), File(N->getRawFile()),
00705         Line(N->getLine()), Type(N->getRawType()),
00706         IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
00707         Variable(N->getRawVariable()),
00708         StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
00709 
00710   bool isKeyOf(const MDGlobalVariable *RHS) const {
00711     return Scope == RHS->getRawScope() && Name == RHS->getName() &&
00712            LinkageName == RHS->getLinkageName() && File == RHS->getRawFile() &&
00713            Line == RHS->getLine() && Type == RHS->getRawType() &&
00714            IsLocalToUnit == RHS->isLocalToUnit() &&
00715            IsDefinition == RHS->isDefinition() &&
00716            Variable == RHS->getRawVariable() &&
00717            StaticDataMemberDeclaration ==
00718                RHS->getRawStaticDataMemberDeclaration();
00719   }
00720   unsigned getHashValue() const {
00721     return hash_combine(Scope, Name, LinkageName, File, Line, Type,
00722                         IsLocalToUnit, IsDefinition, Variable,
00723                         StaticDataMemberDeclaration);
00724   }
00725 };
00726 
00727 template <> struct MDNodeKeyImpl<MDLocalVariable> {
00728   unsigned Tag;
00729   Metadata *Scope;
00730   StringRef Name;
00731   Metadata *File;
00732   unsigned Line;
00733   Metadata *Type;
00734   unsigned Arg;
00735   unsigned Flags;
00736   Metadata *InlinedAt;
00737 
00738   MDNodeKeyImpl(unsigned Tag, Metadata *Scope, StringRef Name, Metadata *File,
00739                 unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags,
00740                 Metadata *InlinedAt)
00741       : Tag(Tag), Scope(Scope), Name(Name), File(File), Line(Line), Type(Type),
00742         Arg(Arg), Flags(Flags), InlinedAt(InlinedAt) {}
00743   MDNodeKeyImpl(const MDLocalVariable *N)
00744       : Tag(N->getTag()), Scope(N->getRawScope()), Name(N->getName()),
00745         File(N->getRawFile()), Line(N->getLine()), Type(N->getRawType()),
00746         Arg(N->getArg()), Flags(N->getFlags()),
00747         InlinedAt(N->getRawInlinedAt()) {}
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            InlinedAt == RHS->getRawInlinedAt();
00755   }
00756   unsigned getHashValue() const {
00757     return hash_combine(Tag, Scope, Name, File, Line, Type, Arg, Flags,
00758                         InlinedAt);
00759   }
00760 };
00761 
00762 template <> struct MDNodeKeyImpl<MDExpression> {
00763   ArrayRef<uint64_t> Elements;
00764 
00765   MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
00766   MDNodeKeyImpl(const MDExpression *N) : Elements(N->getElements()) {}
00767 
00768   bool isKeyOf(const MDExpression *RHS) const {
00769     return Elements == RHS->getElements();
00770   }
00771   unsigned getHashValue() const {
00772     return hash_combine_range(Elements.begin(), Elements.end());
00773   }
00774 };
00775 
00776 template <> struct MDNodeKeyImpl<MDObjCProperty> {
00777   StringRef Name;
00778   Metadata *File;
00779   unsigned Line;
00780   StringRef GetterName;
00781   StringRef SetterName;
00782   unsigned Attributes;
00783   Metadata *Type;
00784 
00785   MDNodeKeyImpl(StringRef Name, Metadata *File, unsigned Line,
00786                 StringRef GetterName, StringRef SetterName, unsigned Attributes,
00787                 Metadata *Type)
00788       : Name(Name), File(File), Line(Line), GetterName(GetterName),
00789         SetterName(SetterName), Attributes(Attributes), Type(Type) {}
00790   MDNodeKeyImpl(const MDObjCProperty *N)
00791       : Name(N->getName()), File(N->getFile()), Line(N->getLine()),
00792         GetterName(N->getGetterName()), SetterName(N->getSetterName()),
00793         Attributes(N->getAttributes()), Type(N->getType()) {}
00794 
00795   bool isKeyOf(const MDObjCProperty *RHS) const {
00796     return Name == RHS->getName() && File == RHS->getFile() &&
00797            Line == RHS->getLine() && GetterName == RHS->getGetterName() &&
00798            SetterName == RHS->getSetterName() &&
00799            Attributes == RHS->getAttributes() && Type == RHS->getType();
00800   }
00801   unsigned getHashValue() const {
00802     return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
00803                         Type);
00804   }
00805 };
00806 
00807 template <> struct MDNodeKeyImpl<MDImportedEntity> {
00808   unsigned Tag;
00809   Metadata *Scope;
00810   Metadata *Entity;
00811   unsigned Line;
00812   StringRef Name;
00813 
00814   MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
00815                 StringRef Name)
00816       : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
00817   MDNodeKeyImpl(const MDImportedEntity *N)
00818       : Tag(N->getTag()), Scope(N->getScope()), Entity(N->getEntity()),
00819         Line(N->getLine()), Name(N->getName()) {}
00820 
00821   bool isKeyOf(const MDImportedEntity *RHS) const {
00822     return Tag == RHS->getTag() && Scope == RHS->getScope() &&
00823            Entity == RHS->getEntity() && Line == RHS->getLine() &&
00824            Name == RHS->getName();
00825   }
00826   unsigned getHashValue() const {
00827     return hash_combine(Tag, Scope, Entity, Line, Name);
00828   }
00829 };
00830 
00831 /// \brief DenseMapInfo for MDNode subclasses.
00832 template <class NodeTy> struct MDNodeInfo {
00833   typedef MDNodeKeyImpl<NodeTy> KeyTy;
00834   static inline NodeTy *getEmptyKey() {
00835     return DenseMapInfo<NodeTy *>::getEmptyKey();
00836   }
00837   static inline NodeTy *getTombstoneKey() {
00838     return DenseMapInfo<NodeTy *>::getTombstoneKey();
00839   }
00840   static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
00841   static unsigned getHashValue(const NodeTy *N) {
00842     return KeyTy(N).getHashValue();
00843   }
00844   static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
00845     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
00846       return false;
00847     return LHS.isKeyOf(RHS);
00848   }
00849   static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
00850     return LHS == RHS;
00851   }
00852 };
00853 
00854 #define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
00855 #include "llvm/IR/Metadata.def"
00856 
00857 class LLVMContextImpl {
00858 public:
00859   /// OwnedModules - The set of modules instantiated in this context, and which
00860   /// will be automatically deleted if this context is deleted.
00861   SmallPtrSet<Module*, 4> OwnedModules;
00862   
00863   LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
00864   void *InlineAsmDiagContext;
00865 
00866   LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
00867   void *DiagnosticContext;
00868   bool RespectDiagnosticFilters;
00869 
00870   LLVMContext::YieldCallbackTy YieldCallback;
00871   void *YieldOpaqueHandle;
00872 
00873   typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
00874   IntMapTy IntConstants;
00875 
00876   typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
00877   FPMapTy FPConstants;
00878 
00879   FoldingSet<AttributeImpl> AttrsSet;
00880   FoldingSet<AttributeSetImpl> AttrsLists;
00881   FoldingSet<AttributeSetNode> AttrsSetNodes;
00882 
00883   StringMap<MDString> MDStringCache;
00884   DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
00885   DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
00886 
00887 #define HANDLE_MDNODE_LEAF(CLASS) DenseSet<CLASS *, CLASS##Info> CLASS##s;
00888 #include "llvm/IR/Metadata.def"
00889 
00890   // MDNodes may be uniqued or not uniqued.  When they're not uniqued, they
00891   // aren't in the MDNodeSet, but they're still shared between objects, so no
00892   // one object can destroy them.  This set allows us to at least destroy them
00893   // on Context destruction.
00894   SmallPtrSet<MDNode *, 1> DistinctMDNodes;
00895 
00896   DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
00897 
00898   typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
00899   ArrayConstantsTy ArrayConstants;
00900   
00901   typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
00902   StructConstantsTy StructConstants;
00903   
00904   typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
00905   VectorConstantsTy VectorConstants;
00906   
00907   DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
00908 
00909   DenseMap<Type*, UndefValue*> UVConstants;
00910   
00911   StringMap<ConstantDataSequential*> CDSConstants;
00912 
00913   DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
00914     BlockAddresses;
00915   ConstantUniqueMap<ConstantExpr> ExprConstants;
00916 
00917   ConstantUniqueMap<InlineAsm> InlineAsms;
00918 
00919   ConstantInt *TheTrueVal;
00920   ConstantInt *TheFalseVal;
00921 
00922   // Basic type instances.
00923   Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy;
00924   Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
00925   IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty;
00926 
00927   
00928   /// TypeAllocator - All dynamically allocated types are allocated from this.
00929   /// They live forever until the context is torn down.
00930   BumpPtrAllocator TypeAllocator;
00931   
00932   DenseMap<unsigned, IntegerType*> IntegerTypes;
00933 
00934   typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
00935   FunctionTypeSet FunctionTypes;
00936   typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
00937   StructTypeSet AnonStructTypes;
00938   StringMap<StructType*> NamedStructTypes;
00939   unsigned NamedStructTypesUniqueID;
00940     
00941   DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
00942   DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
00943   DenseMap<Type*, PointerType*> PointerTypes;  // Pointers in AddrSpace = 0
00944   DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
00945 
00946 
00947   /// ValueHandles - This map keeps track of all of the value handles that are
00948   /// watching a Value*.  The Value::HasValueHandle bit is used to know
00949   /// whether or not a value has an entry in this map.
00950   typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
00951   ValueHandlesTy ValueHandles;
00952   
00953   /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
00954   StringMap<unsigned> CustomMDKindNames;
00955 
00956   typedef std::pair<unsigned, TrackingMDNodeRef> MDPairTy;
00957   typedef SmallVector<MDPairTy, 2> MDMapTy;
00958 
00959   /// MetadataStore - Collection of per-instruction metadata used in this
00960   /// context.
00961   DenseMap<const Instruction *, MDMapTy> MetadataStore;
00962   
00963   /// DiscriminatorTable - This table maps file:line locations to an
00964   /// integer representing the next DWARF path discriminator to assign to
00965   /// instructions in different blocks at the same location.
00966   DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
00967 
00968   /// IntrinsicIDCache - Cache of intrinsic name (string) to numeric ID mappings
00969   /// requested in this context
00970   typedef DenseMap<const Function*, unsigned> IntrinsicIDCacheTy;
00971   IntrinsicIDCacheTy IntrinsicIDCache;
00972 
00973   /// \brief Mapping from a function to its prefix data, which is stored as the
00974   /// operand of an unparented ReturnInst so that the prefix data has a Use.
00975   typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy;
00976   PrefixDataMapTy PrefixDataMap;
00977 
00978   /// \brief Mapping from a function to its prologue data, which is stored as
00979   /// the operand of an unparented ReturnInst so that the prologue data has a
00980   /// Use.
00981   typedef DenseMap<const Function *, ReturnInst *> PrologueDataMapTy;
00982   PrologueDataMapTy PrologueDataMap;
00983 
00984   int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
00985   int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
00986 
00987   LLVMContextImpl(LLVMContext &C);
00988   ~LLVMContextImpl();
00989 
00990   /// Destroy the ConstantArrays if they are not used.
00991   void dropTriviallyDeadConstantArrays();
00992 };
00993 
00994 }
00995 
00996 #endif