LLVMContextImpl.h revision 1e3037f0be430ef2339838bbdede11f45658bd82
12f1efd639c8659582d0df2b8f927a018b057037fJeffrey Yasskin//===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===// 22bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson// 32bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson// The LLVM Compiler Infrastructure 42bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson// 52bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson// This file is distributed under the University of Illinois Open Source 62bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson// License. See LICENSE.TXT for details. 72bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson// 82bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson//===----------------------------------------------------------------------===// 95217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson// 105217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson// This file declares LLVMContextImpl, the opaque implementation 115217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson// of LLVMContext. 125217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson// 135217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson//===----------------------------------------------------------------------===// 142bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson 152bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson#ifndef LLVM_LLVMCONTEXT_IMPL_H 162bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson#define LLVM_LLVMCONTEXT_IMPL_H 172bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson 18f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling#include "AttributeImpl.h" 1948b2f3e4850cd27d54224cd42da8a160d6b95984Owen Anderson#include "ConstantsContext.h" 20c34ebf65af0139eaf5cb0969fabcd32c0b6e1710Owen Anderson#include "LeaksContext.h" 21914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson#include "llvm/ADT/APFloat.h" 22001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson#include "llvm/ADT/APInt.h" 232a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad#include "llvm/ADT/ArrayRef.h" 24001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson#include "llvm/ADT/DenseMap.h" 25ce032b483ca96093b84f69178cdb2d047e124332Owen Anderson#include "llvm/ADT/FoldingSet.h" 26a1514e24cc24b050f53a12650e047799358833a1Chandler Carruth#include "llvm/ADT/Hashing.h" 27ad715f86c90b06cc4ab9e1336d1bc3bf13ecb16dJeffrey Yasskin#include "llvm/ADT/SmallPtrSet.h" 28aad3fb7362aff151e97ad457005ea3f2872fe868Owen Anderson#include "llvm/ADT/StringMap.h" 290b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Constants.h" 300b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/DerivedTypes.h" 310b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/LLVMContext.h" 320b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Metadata.h" 33a1514e24cc24b050f53a12650e047799358833a1Chandler Carruth#include "llvm/Support/ValueHandle.h" 34006c77df8cc7f6a9dac575600b797b8ba32b29ebOwen Anderson#include <vector> 3516e298f98024bcff5c7219a96cac216114c30dadOwen Anderson 362bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Andersonnamespace llvm { 37eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 38001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Andersonclass ConstantInt; 39914e50c841bbc248ab94144c11813b5785b1292dOwen Andersonclass ConstantFP; 4012ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContext; 41001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Andersonclass Type; 42ce032b483ca96093b84f69178cdb2d047e124332Owen Andersonclass Value; 43001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson 4455c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerstruct DenseMapAPIntKeyInfo { 45001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson struct KeyTy { 46001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson APInt val; 47db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type* type; 48db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner KeyTy(const APInt& V, Type* Ty) : val(V), type(Ty) {} 49001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson bool operator==(const KeyTy& that) const { 50001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson return type == that.type && this->val == that.val; 51001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson } 52001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson bool operator!=(const KeyTy& that) const { 53001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson return !this->operator==(that); 54001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson } 55ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth friend hash_code hash_value(const KeyTy &Key) { 56ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth return hash_combine(Key.type, Key.val); 57ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth } 58001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson }; 59001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson static inline KeyTy getEmptyKey() { return KeyTy(APInt(1,0), 0); } 60001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson static inline KeyTy getTombstoneKey() { return KeyTy(APInt(1,1), 0); } 61001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson static unsigned getHashValue(const KeyTy &Key) { 62ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth return static_cast<unsigned>(hash_value(Key)); 63001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson } 64001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { 65001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson return LHS == RHS; 66001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson } 67001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson}; 68001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson 6955c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerstruct DenseMapAPFloatKeyInfo { 70914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson struct KeyTy { 71914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson APFloat val; 72914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson KeyTy(const APFloat& V) : val(V){} 73914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson bool operator==(const KeyTy& that) const { 74914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return this->val.bitwiseIsEqual(that.val); 75914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 76914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson bool operator!=(const KeyTy& that) const { 77914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return !this->operator==(that); 78914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 79ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth friend hash_code hash_value(const KeyTy &Key) { 80ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth return hash_combine(Key.val); 81ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth } 82914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson }; 83914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static inline KeyTy getEmptyKey() { 84914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return KeyTy(APFloat(APFloat::Bogus,1)); 85914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 86914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static inline KeyTy getTombstoneKey() { 87914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return KeyTy(APFloat(APFloat::Bogus,2)); 88914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 89914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static unsigned getHashValue(const KeyTy &Key) { 90ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth return static_cast<unsigned>(hash_value(Key)); 91914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 92914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { 93914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return LHS == RHS; 94914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 95914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson}; 96914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson 9755c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerstruct AnonStructTypeKeyInfo { 98bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad struct KeyTy { 99bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ArrayRef<Type*> ETypes; 100bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool isPacked; 101bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const ArrayRef<Type*>& E, bool P) : 102bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ETypes(E), isPacked(P) {} 103bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const StructType* ST) : 104bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ETypes(ArrayRef<Type*>(ST->element_begin(), ST->element_end())), 105bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad isPacked(ST->isPacked()) {} 106bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator==(const KeyTy& that) const { 107bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (isPacked != that.isPacked) 108bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 109bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (ETypes != that.ETypes) 110bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 111bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return true; 112bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 113bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator!=(const KeyTy& that) const { 114bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return !this->operator==(that); 115bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 116bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad }; 117bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline StructType* getEmptyKey() { 118bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<StructType*>::getEmptyKey(); 119bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 120bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline StructType* getTombstoneKey() { 121bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<StructType*>::getTombstoneKey(); 122bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 123bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const KeyTy& Key) { 1240b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth return hash_combine(hash_combine_range(Key.ETypes.begin(), 1250b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.ETypes.end()), 1260b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.isPacked); 127bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 128bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const StructType *ST) { 129bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return getHashValue(KeyTy(ST)); 130bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 131bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const KeyTy& LHS, const StructType *RHS) { 132bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 133bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 134bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == KeyTy(RHS); 135bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 136bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const StructType *LHS, const StructType *RHS) { 137bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == RHS; 138bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 139bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad}; 140bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad 14155c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerstruct FunctionTypeKeyInfo { 142bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad struct KeyTy { 143bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad const Type *ReturnType; 144bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ArrayRef<Type*> Params; 145bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool isVarArg; 146bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) : 147bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ReturnType(R), Params(P), isVarArg(V) {} 148bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const FunctionType* FT) : 149bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ReturnType(FT->getReturnType()), 150bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad Params(ArrayRef<Type*>(FT->param_begin(), FT->param_end())), 151bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad isVarArg(FT->isVarArg()) {} 152bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator==(const KeyTy& that) const { 153bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (ReturnType != that.ReturnType) 154bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 155bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (isVarArg != that.isVarArg) 156bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 157bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (Params != that.Params) 158bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 159bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return true; 160bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 161bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator!=(const KeyTy& that) const { 162bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return !this->operator==(that); 163bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 164bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad }; 165bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline FunctionType* getEmptyKey() { 166bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<FunctionType*>::getEmptyKey(); 167bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 168bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline FunctionType* getTombstoneKey() { 169bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<FunctionType*>::getTombstoneKey(); 170bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 171bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const KeyTy& Key) { 1720b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth return hash_combine(Key.ReturnType, 1730b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth hash_combine_range(Key.Params.begin(), 1740b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.Params.end()), 1750b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.isVarArg); 176bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 177bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const FunctionType *FT) { 178bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return getHashValue(KeyTy(FT)); 179bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 180bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) { 181bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 182bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 183bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == KeyTy(RHS); 184bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 185bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { 186bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == RHS; 187bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 188bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad}; 189bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad 190611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer// Provide a FoldingSetTrait::Equals specialization for MDNode that can use a 191611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer// shortcut to avoid comparing all operands. 192611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramertemplate<> struct FoldingSetTrait<MDNode> : DefaultFoldingSetTrait<MDNode> { 193611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer static bool Equals(const MDNode &X, const FoldingSetNodeID &ID, 194611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer unsigned IDHash, FoldingSetNodeID &TempID) { 195611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer assert(!X.isNotUniqued() && "Non-uniqued MDNode in FoldingSet?"); 196611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer // First, check if the cached hashes match. If they don't we can skip the 197611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer // expensive operand walk. 198611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer if (X.Hash != IDHash) 199611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer return false; 200611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer 201611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer // If they match we have to compare the operands. 202611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer X.Profile(TempID); 203611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer return TempID == ID; 204611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer } 205611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer static unsigned ComputeHash(const MDNode &X, FoldingSetNodeID &) { 206611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer return X.Hash; // Return cached hash. 207611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer } 208611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer}; 209611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer 210b227925fa313428045f554187b0136d084d723f6Chris Lattner/// DebugRecVH - This is a CallbackVH used to keep the Scope -> index maps 211b227925fa313428045f554187b0136d084d723f6Chris Lattner/// up to date as MDNodes mutate. This class is implemented in DebugLoc.cpp. 21255c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerclass DebugRecVH : public CallbackVH { 213b227925fa313428045f554187b0136d084d723f6Chris Lattner /// Ctx - This is the LLVM Context being referenced. 214b227925fa313428045f554187b0136d084d723f6Chris Lattner LLVMContextImpl *Ctx; 215b227925fa313428045f554187b0136d084d723f6Chris Lattner 216b227925fa313428045f554187b0136d084d723f6Chris Lattner /// Idx - The index into either ScopeRecordIdx or ScopeInlinedAtRecords that 217b227925fa313428045f554187b0136d084d723f6Chris Lattner /// this reference lives in. If this is zero, then it represents a 218b227925fa313428045f554187b0136d084d723f6Chris Lattner /// non-canonical entry that has no DenseMap value. This can happen due to 219b227925fa313428045f554187b0136d084d723f6Chris Lattner /// RAUW. 220b227925fa313428045f554187b0136d084d723f6Chris Lattner int Idx; 221b227925fa313428045f554187b0136d084d723f6Chris Lattnerpublic: 222b227925fa313428045f554187b0136d084d723f6Chris Lattner DebugRecVH(MDNode *n, LLVMContextImpl *ctx, int idx) 223b227925fa313428045f554187b0136d084d723f6Chris Lattner : CallbackVH(n), Ctx(ctx), Idx(idx) {} 224b227925fa313428045f554187b0136d084d723f6Chris Lattner 225b227925fa313428045f554187b0136d084d723f6Chris Lattner MDNode *get() const { 226b227925fa313428045f554187b0136d084d723f6Chris Lattner return cast_or_null<MDNode>(getValPtr()); 227b227925fa313428045f554187b0136d084d723f6Chris Lattner } 228b227925fa313428045f554187b0136d084d723f6Chris Lattner 229b227925fa313428045f554187b0136d084d723f6Chris Lattner virtual void deleted(); 230b227925fa313428045f554187b0136d084d723f6Chris Lattner virtual void allUsesReplacedWith(Value *VNew); 231b227925fa313428045f554187b0136d084d723f6Chris Lattner}; 232b227925fa313428045f554187b0136d084d723f6Chris Lattner 23355c06ae7afa3f862a6bb4a4441fe485c135f5b5eBenjamin Kramerclass LLVMContextImpl { 23412ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerpublic: 23530268be89df6444f5ffb585439b3fbfec9055197Owen Anderson /// OwnedModules - The set of modules instantiated in this context, and which 23630268be89df6444f5ffb585439b3fbfec9055197Owen Anderson /// will be automatically deleted if this context is deleted. 23730268be89df6444f5ffb585439b3fbfec9055197Owen Anderson SmallPtrSet<Module*, 4> OwnedModules; 23830268be89df6444f5ffb585439b3fbfec9055197Owen Anderson 239f64c889cc94417322b0ff8ad1c61939183bf3c38Bob Wilson LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler; 240f64c889cc94417322b0ff8ad1c61939183bf3c38Bob Wilson void *InlineAsmDiagContext; 24142a4ee0a35b4672311c1b988bd883167de9f88cdChris Lattner 242001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*, 24348b2f3e4850cd27d54224cd42da8a160d6b95984Owen Anderson DenseMapAPIntKeyInfo> IntMapTy; 244001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson IntMapTy IntConstants; 245001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson 246914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, 24748b2f3e4850cd27d54224cd42da8a160d6b95984Owen Anderson DenseMapAPFloatKeyInfo> FPMapTy; 248914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson FPMapTy FPConstants; 2492c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 250f6670729aabc1fab85238d2b306a1c1767a807bbBill Wendling FoldingSet<AttributeImpl> AttrsSet; 25118e7211068c9d2c6204512f9c468ee179818a4b6Bill Wendling FoldingSet<AttributeSetImpl> AttrsLists; 2523467e30edf63b6d8a8d446186674ba9e4b7885a9Bill Wendling FoldingSet<AttributeSetNode> AttrsSetNodes; 2530976e00fd1cbf4128daeb72efd8957d00383fda9Bill Wendling 2543ecb447f52d169dea6663b95b5b5b43e9bb5826bBill Wendling StringMap<Value*> MDStringCache; 2552c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 2565f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel FoldingSet<MDNode> MDNodeSet; 2572c79ecbd704c656178ffa43d5a58ebe3ca188b40Bill Wendling 2586f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // MDNodes may be uniqued or not uniqued. When they're not uniqued, they 2596f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // aren't in the MDNodeSet, but they're still shared between objects, so no 2606f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // one object can destroy them. This set allows us to at least destroy them 2616f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // on Context destruction. 2626f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin SmallPtrSet<MDNode*, 1> NonUniquedMDNodes; 2635f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel 2649df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner DenseMap<Type*, ConstantAggregateZero*> CAZConstants; 2650631fce85050f8f633e5fd032875d9151e0db4daOwen Anderson 2662cb395eae71dacda49ca3fe758618fc3e0701659Talin typedef ConstantAggrUniqueMap<ArrayType, ConstantArray> ArrayConstantsTy; 267eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson ArrayConstantsTy ArrayConstants; 26816e298f98024bcff5c7219a96cac216114c30dadOwen Anderson 2692cb395eae71dacda49ca3fe758618fc3e0701659Talin typedef ConstantAggrUniqueMap<StructType, ConstantStruct> StructConstantsTy; 270eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson StructConstantsTy StructConstants; 271006c77df8cc7f6a9dac575600b797b8ba32b29ebOwen Anderson 2722cb395eae71dacda49ca3fe758618fc3e0701659Talin typedef ConstantAggrUniqueMap<VectorType, ConstantVector> VectorConstantsTy; 273eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson VectorConstantsTy VectorConstants; 2745bd68393ed87bcedc53f5998f1af9c906f5a1b4eOwen Anderson 2759df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner DenseMap<PointerType*, ConstantPointerNull*> CPNConstants; 2769df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner 2779df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner DenseMap<Type*, UndefValue*> UVConstants; 2787e3142b0126abc86dc4da350e8b84b001c3eeddeOwen Anderson 27927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner StringMap<ConstantDataSequential*> CDSConstants; 28027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 28127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 2822ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses; 2832a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad ConstantUniqueMap<ExprMapKeyType, const ExprMapKeyType&, Type, ConstantExpr> 2842a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad ExprConstants; 285bf48a9b6db111fc14a8faef1adefbce5d807aaefJeffrey Yasskin 2862a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad ConstantUniqueMap<InlineAsmKeyType, const InlineAsmKeyType&, PointerType, 2872a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad InlineAsm> InlineAsms; 288d03eecd063a18ce0c505a87afcb04db26c035bc9Owen Anderson 289f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson ConstantInt *TheTrueVal; 290f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson ConstantInt *TheFalseVal; 291f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson 292c34ebf65af0139eaf5cb0969fabcd32c0b6e1710Owen Anderson LeakDetectorImpl<Value> LLVMObjects; 293c34ebf65af0139eaf5cb0969fabcd32c0b6e1710Owen Anderson 29463a03cf58505aa839f721f212cd1518ebf133979Dan Gohman // Basic type instances. 295ce16339930a2b03e53b4e6399ef59c092a7f2cfaDan Gohman Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy; 2961afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; 2971afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty; 2989233b15d01ca62445bfc638f782243988c672e01Jeffrey Yasskin 299ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner 300ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner /// TypeAllocator - All dynamically allocated types are allocated from this. 301ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner /// They live forever until the context is torn down. 302ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner BumpPtrAllocator TypeAllocator; 303ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner 3041afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<unsigned, IntegerType*> IntegerTypes; 3051afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 306bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad typedef DenseMap<FunctionType*, bool, FunctionTypeKeyInfo> FunctionTypeMap; 307bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad FunctionTypeMap FunctionTypes; 308bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad typedef DenseMap<StructType*, bool, AnonStructTypeKeyInfo> StructTypeMap; 309bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad StructTypeMap AnonStructTypes; 3101afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner StringMap<StructType*> NamedStructTypes; 3111afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner unsigned NamedStructTypesUniqueID; 3121afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 3131afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes; 3141afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes; 3151afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0 3161afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes; 3179233b15d01ca62445bfc638f782243988c672e01Jeffrey Yasskin 318ad715f86c90b06cc4ab9e1336d1bc3bf13ecb16dJeffrey Yasskin 3194d919438898d542850449235da7f6dc55e6ca152Owen Anderson /// ValueHandles - This map keeps track of all of the value handles that are 3204d919438898d542850449235da7f6dc55e6ca152Owen Anderson /// watching a Value*. The Value::HasValueHandle bit is used to know 3214c8e74f0b75cb10820c45c86399fbd02e4a8832aMichael Ilseman /// whether or not a value has an entry in this map. 3224d919438898d542850449235da7f6dc55e6ca152Owen Anderson typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy; 3234d919438898d542850449235da7f6dc55e6ca152Owen Anderson ValueHandlesTy ValueHandles; 3244d919438898d542850449235da7f6dc55e6ca152Owen Anderson 325081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// CustomMDKindNames - Map to hold the metadata string to ID mapping. 326081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner StringMap<unsigned> CustomMDKindNames; 327081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner 328081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy; 329081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner typedef SmallVector<MDPairTy, 2> MDMapTy; 330081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner 331081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// MetadataStore - Collection of per-instruction metadata used in this 332081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// context. 333081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner DenseMap<const Instruction *, MDMapTy> MetadataStore; 334081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner 335b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeRecordIdx - This is the index in ScopeRecords for an MDNode scope 336b227925fa313428045f554187b0136d084d723f6Chris Lattner /// entry with no "inlined at" element. 337b227925fa313428045f554187b0136d084d723f6Chris Lattner DenseMap<MDNode*, int> ScopeRecordIdx; 338b227925fa313428045f554187b0136d084d723f6Chris Lattner 339b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeRecords - These are the actual mdnodes (in a value handle) for an 340b227925fa313428045f554187b0136d084d723f6Chris Lattner /// index. The ValueHandle ensures that ScopeRecordIdx stays up to date if 341b227925fa313428045f554187b0136d084d723f6Chris Lattner /// the MDNode is RAUW'd. 342b227925fa313428045f554187b0136d084d723f6Chris Lattner std::vector<DebugRecVH> ScopeRecords; 343b227925fa313428045f554187b0136d084d723f6Chris Lattner 344b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeInlinedAtIdx - This is the index in ScopeInlinedAtRecords for an 345b227925fa313428045f554187b0136d084d723f6Chris Lattner /// scope/inlined-at pair. 346b227925fa313428045f554187b0136d084d723f6Chris Lattner DenseMap<std::pair<MDNode*, MDNode*>, int> ScopeInlinedAtIdx; 347b227925fa313428045f554187b0136d084d723f6Chris Lattner 348b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeInlinedAtRecords - These are the actual mdnodes (in value handles) 349b227925fa313428045f554187b0136d084d723f6Chris Lattner /// for an index. The ValueHandle ensures that ScopeINlinedAtIdx stays up 350b227925fa313428045f554187b0136d084d723f6Chris Lattner /// to date. 351b227925fa313428045f554187b0136d084d723f6Chris Lattner std::vector<std::pair<DebugRecVH, DebugRecVH> > ScopeInlinedAtRecords; 352b227925fa313428045f554187b0136d084d723f6Chris Lattner 3534c8e74f0b75cb10820c45c86399fbd02e4a8832aMichael Ilseman /// IntrinsicIDCache - Cache of intrinsic name (string) to numeric ID mappings 3544c8e74f0b75cb10820c45c86399fbd02e4a8832aMichael Ilseman /// requested in this context 3554c8e74f0b75cb10820c45c86399fbd02e4a8832aMichael Ilseman typedef DenseMap<const Function*, unsigned> IntrinsicIDCacheTy; 3564c8e74f0b75cb10820c45c86399fbd02e4a8832aMichael Ilseman IntrinsicIDCacheTy IntrinsicIDCache; 3574c8e74f0b75cb10820c45c86399fbd02e4a8832aMichael Ilseman 3581e3037f0be430ef2339838bbdede11f45658bd82Peter Collingbourne /// \brief Mapping from a function to its prefix data, which is stored as the 3591e3037f0be430ef2339838bbdede11f45658bd82Peter Collingbourne /// operand of an unparented ReturnInst so that the prefix data has a Use. 3601e3037f0be430ef2339838bbdede11f45658bd82Peter Collingbourne typedef DenseMap<const Function *, ReturnInst *> PrefixDataMapTy; 3611e3037f0be430ef2339838bbdede11f45658bd82Peter Collingbourne PrefixDataMapTy PrefixDataMap; 3621e3037f0be430ef2339838bbdede11f45658bd82Peter Collingbourne 363b227925fa313428045f554187b0136d084d723f6Chris Lattner int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx); 364b227925fa313428045f554187b0136d084d723f6Chris Lattner int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx); 365b227925fa313428045f554187b0136d084d723f6Chris Lattner 3662f1efd639c8659582d0df2b8f927a018b057037fJeffrey Yasskin LLVMContextImpl(LLVMContext &C); 3672f1efd639c8659582d0df2b8f927a018b057037fJeffrey Yasskin ~LLVMContextImpl(); 3682bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson}; 3692bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson 3702bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson} 3712bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson 3725217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson#endif 373