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 181afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner#include "llvm/LLVMContext.h" 1948b2f3e4850cd27d54224cd42da8a160d6b95984Owen Anderson#include "ConstantsContext.h" 20c34ebf65af0139eaf5cb0969fabcd32c0b6e1710Owen Anderson#include "LeaksContext.h" 21eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson#include "llvm/Constants.h" 22f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson#include "llvm/DerivedTypes.h" 23b4cc66d7b71357d379257930f96929e26697805dJeffrey Yasskin#include "llvm/Metadata.h" 24081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner#include "llvm/Support/ValueHandle.h" 25914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson#include "llvm/ADT/APFloat.h" 26001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson#include "llvm/ADT/APInt.h" 272a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad#include "llvm/ADT/ArrayRef.h" 28001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson#include "llvm/ADT/DenseMap.h" 29ce032b483ca96093b84f69178cdb2d047e124332Owen Anderson#include "llvm/ADT/FoldingSet.h" 30ad715f86c90b06cc4ab9e1336d1bc3bf13ecb16dJeffrey Yasskin#include "llvm/ADT/SmallPtrSet.h" 31aad3fb7362aff151e97ad457005ea3f2872fe868Owen Anderson#include "llvm/ADT/StringMap.h" 32bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad#include "llvm/ADT/Hashing.h" 33006c77df8cc7f6a9dac575600b797b8ba32b29ebOwen Anderson#include <vector> 3416e298f98024bcff5c7219a96cac216114c30dadOwen Anderson 352bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Andersonnamespace llvm { 36eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 37001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Andersonclass ConstantInt; 38914e50c841bbc248ab94144c11813b5785b1292dOwen Andersonclass ConstantFP; 3912ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContext; 40001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Andersonclass Type; 41ce032b483ca96093b84f69178cdb2d047e124332Owen Andersonclass Value; 42001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson 43001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Andersonstruct DenseMapAPIntKeyInfo { 44001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson struct KeyTy { 45001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson APInt val; 46db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type* type; 47db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner KeyTy(const APInt& V, Type* Ty) : val(V), type(Ty) {} 48001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson KeyTy(const KeyTy& that) : val(that.val), type(that.type) {} 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 69914e50c841bbc248ab94144c11813b5785b1292dOwen Andersonstruct DenseMapAPFloatKeyInfo { 70914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson struct KeyTy { 71914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson APFloat val; 72914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson KeyTy(const APFloat& V) : val(V){} 73914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson KeyTy(const KeyTy& that) : val(that.val) {} 74914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson bool operator==(const KeyTy& that) const { 75914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return this->val.bitwiseIsEqual(that.val); 76914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 77914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson bool operator!=(const KeyTy& that) const { 78914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return !this->operator==(that); 79914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 80ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth friend hash_code hash_value(const KeyTy &Key) { 81ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth return hash_combine(Key.val); 82ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth } 83914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson }; 84914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static inline KeyTy getEmptyKey() { 85914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return KeyTy(APFloat(APFloat::Bogus,1)); 86914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 87914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static inline KeyTy getTombstoneKey() { 88914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return KeyTy(APFloat(APFloat::Bogus,2)); 89914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 90914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static unsigned getHashValue(const KeyTy &Key) { 91ed7692a136a9bcf513b91b7b5eb33a1e2d83e7eeChandler Carruth return static_cast<unsigned>(hash_value(Key)); 92914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 93914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson static bool isEqual(const KeyTy &LHS, const KeyTy &RHS) { 94914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson return LHS == RHS; 95914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson } 96914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson}; 97914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson 98bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foadstruct AnonStructTypeKeyInfo { 99bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad struct KeyTy { 100bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ArrayRef<Type*> ETypes; 101bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool isPacked; 102bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const ArrayRef<Type*>& E, bool P) : 103bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ETypes(E), isPacked(P) {} 104bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const KeyTy& that) : 105bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ETypes(that.ETypes), isPacked(that.isPacked) {} 106bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const StructType* ST) : 107bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ETypes(ArrayRef<Type*>(ST->element_begin(), ST->element_end())), 108bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad isPacked(ST->isPacked()) {} 109bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator==(const KeyTy& that) const { 110bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (isPacked != that.isPacked) 111bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 112bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (ETypes != that.ETypes) 113bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 114bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return true; 115bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 116bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator!=(const KeyTy& that) const { 117bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return !this->operator==(that); 118bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 119bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad }; 120bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline StructType* getEmptyKey() { 121bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<StructType*>::getEmptyKey(); 122bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 123bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline StructType* getTombstoneKey() { 124bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<StructType*>::getTombstoneKey(); 125bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 126bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const KeyTy& Key) { 1270b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth return hash_combine(hash_combine_range(Key.ETypes.begin(), 1280b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.ETypes.end()), 1290b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.isPacked); 130bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 131bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const StructType *ST) { 132bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return getHashValue(KeyTy(ST)); 133bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 134bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const KeyTy& LHS, const StructType *RHS) { 135bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 136bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 137bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == KeyTy(RHS); 138bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 139bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const StructType *LHS, const StructType *RHS) { 140bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == RHS; 141bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 142bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad}; 143bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad 144bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foadstruct FunctionTypeKeyInfo { 145bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad struct KeyTy { 146bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad const Type *ReturnType; 147bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ArrayRef<Type*> Params; 148bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool isVarArg; 149bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) : 150bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ReturnType(R), Params(P), isVarArg(V) {} 151bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const KeyTy& that) : 152bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ReturnType(that.ReturnType), 153bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad Params(that.Params), 154bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad isVarArg(that.isVarArg) {} 155bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad KeyTy(const FunctionType* FT) : 156bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad ReturnType(FT->getReturnType()), 157bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad Params(ArrayRef<Type*>(FT->param_begin(), FT->param_end())), 158bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad isVarArg(FT->isVarArg()) {} 159bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator==(const KeyTy& that) const { 160bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (ReturnType != that.ReturnType) 161bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 162bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (isVarArg != that.isVarArg) 163bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 164bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (Params != that.Params) 165bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 166bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return true; 167bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 168bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad bool operator!=(const KeyTy& that) const { 169bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return !this->operator==(that); 170bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 171bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad }; 172bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline FunctionType* getEmptyKey() { 173bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<FunctionType*>::getEmptyKey(); 174bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 175bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static inline FunctionType* getTombstoneKey() { 176bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return DenseMapInfo<FunctionType*>::getTombstoneKey(); 177bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 178bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const KeyTy& Key) { 1790b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth return hash_combine(Key.ReturnType, 1800b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth hash_combine_range(Key.Params.begin(), 1810b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.Params.end()), 1820b66c6fca22e85f732cf58f459a06c06833d1882Chandler Carruth Key.isVarArg); 183bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 184bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static unsigned getHashValue(const FunctionType *FT) { 185bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return getHashValue(KeyTy(FT)); 186bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 187bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) { 188bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad if (RHS == getEmptyKey() || RHS == getTombstoneKey()) 189bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return false; 190bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == KeyTy(RHS); 191bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 192bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { 193bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad return LHS == RHS; 194bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad } 195bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad}; 196bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad 197611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer// Provide a FoldingSetTrait::Equals specialization for MDNode that can use a 198611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer// shortcut to avoid comparing all operands. 199611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramertemplate<> struct FoldingSetTrait<MDNode> : DefaultFoldingSetTrait<MDNode> { 200611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer static bool Equals(const MDNode &X, const FoldingSetNodeID &ID, 201611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer unsigned IDHash, FoldingSetNodeID &TempID) { 202611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer assert(!X.isNotUniqued() && "Non-uniqued MDNode in FoldingSet?"); 203611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer // First, check if the cached hashes match. If they don't we can skip the 204611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer // expensive operand walk. 205611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer if (X.Hash != IDHash) 206611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer return false; 207611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer 208611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer // If they match we have to compare the operands. 209611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer X.Profile(TempID); 210611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer return TempID == ID; 211611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer } 212611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer static unsigned ComputeHash(const MDNode &X, FoldingSetNodeID &) { 213611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer return X.Hash; // Return cached hash. 214611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer } 215611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer}; 216611afc0620aed7827b5fdf9072a1827952b684b6Benjamin Kramer 217b227925fa313428045f554187b0136d084d723f6Chris Lattner/// DebugRecVH - This is a CallbackVH used to keep the Scope -> index maps 218b227925fa313428045f554187b0136d084d723f6Chris Lattner/// up to date as MDNodes mutate. This class is implemented in DebugLoc.cpp. 219b227925fa313428045f554187b0136d084d723f6Chris Lattnerclass DebugRecVH : public CallbackVH { 220b227925fa313428045f554187b0136d084d723f6Chris Lattner /// Ctx - This is the LLVM Context being referenced. 221b227925fa313428045f554187b0136d084d723f6Chris Lattner LLVMContextImpl *Ctx; 222b227925fa313428045f554187b0136d084d723f6Chris Lattner 223b227925fa313428045f554187b0136d084d723f6Chris Lattner /// Idx - The index into either ScopeRecordIdx or ScopeInlinedAtRecords that 224b227925fa313428045f554187b0136d084d723f6Chris Lattner /// this reference lives in. If this is zero, then it represents a 225b227925fa313428045f554187b0136d084d723f6Chris Lattner /// non-canonical entry that has no DenseMap value. This can happen due to 226b227925fa313428045f554187b0136d084d723f6Chris Lattner /// RAUW. 227b227925fa313428045f554187b0136d084d723f6Chris Lattner int Idx; 228b227925fa313428045f554187b0136d084d723f6Chris Lattnerpublic: 229b227925fa313428045f554187b0136d084d723f6Chris Lattner DebugRecVH(MDNode *n, LLVMContextImpl *ctx, int idx) 230b227925fa313428045f554187b0136d084d723f6Chris Lattner : CallbackVH(n), Ctx(ctx), Idx(idx) {} 231b227925fa313428045f554187b0136d084d723f6Chris Lattner 232b227925fa313428045f554187b0136d084d723f6Chris Lattner MDNode *get() const { 233b227925fa313428045f554187b0136d084d723f6Chris Lattner return cast_or_null<MDNode>(getValPtr()); 234b227925fa313428045f554187b0136d084d723f6Chris Lattner } 235b227925fa313428045f554187b0136d084d723f6Chris Lattner 236b227925fa313428045f554187b0136d084d723f6Chris Lattner virtual void deleted(); 237b227925fa313428045f554187b0136d084d723f6Chris Lattner virtual void allUsesReplacedWith(Value *VNew); 238b227925fa313428045f554187b0136d084d723f6Chris Lattner}; 239b227925fa313428045f554187b0136d084d723f6Chris Lattner 24012ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerclass LLVMContextImpl { 24112ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramerpublic: 24230268be89df6444f5ffb585439b3fbfec9055197Owen Anderson /// OwnedModules - The set of modules instantiated in this context, and which 24330268be89df6444f5ffb585439b3fbfec9055197Owen Anderson /// will be automatically deleted if this context is deleted. 24430268be89df6444f5ffb585439b3fbfec9055197Owen Anderson SmallPtrSet<Module*, 4> OwnedModules; 24530268be89df6444f5ffb585439b3fbfec9055197Owen Anderson 2464afa12890f679034e9741a687a6ce33f2846f129Chris Lattner LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler; 2474afa12890f679034e9741a687a6ce33f2846f129Chris Lattner void *InlineAsmDiagContext; 24842a4ee0a35b4672311c1b988bd883167de9f88cdChris Lattner 249001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*, 25048b2f3e4850cd27d54224cd42da8a160d6b95984Owen Anderson DenseMapAPIntKeyInfo> IntMapTy; 251001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson IntMapTy IntConstants; 252001dbfebcbbded8c8e74b19e838b50da2b6c6fb5Owen Anderson 253914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*, 25448b2f3e4850cd27d54224cd42da8a160d6b95984Owen Anderson DenseMapAPFloatKeyInfo> FPMapTy; 255914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson FPMapTy FPConstants; 256914e50c841bbc248ab94144c11813b5785b1292dOwen Anderson 2573ecb447f52d169dea6663b95b5b5b43e9bb5826bBill Wendling StringMap<Value*> MDStringCache; 258aad3fb7362aff151e97ad457005ea3f2872fe868Owen Anderson 2595f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel FoldingSet<MDNode> MDNodeSet; 2606f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // MDNodes may be uniqued or not uniqued. When they're not uniqued, they 2616f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // aren't in the MDNodeSet, but they're still shared between objects, so no 2626f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // one object can destroy them. This set allows us to at least destroy them 2636f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin // on Context destruction. 2646f555ca2cd0bba50542adcbb131f541ae70d34cdJeffrey Yasskin SmallPtrSet<MDNode*, 1> NonUniquedMDNodes; 2655f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel 2669df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner DenseMap<Type*, ConstantAggregateZero*> CAZConstants; 2670631fce85050f8f633e5fd032875d9151e0db4daOwen Anderson 2682cb395eae71dacda49ca3fe758618fc3e0701659Talin typedef ConstantAggrUniqueMap<ArrayType, ConstantArray> ArrayConstantsTy; 269eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson ArrayConstantsTy ArrayConstants; 27016e298f98024bcff5c7219a96cac216114c30dadOwen Anderson 2712cb395eae71dacda49ca3fe758618fc3e0701659Talin typedef ConstantAggrUniqueMap<StructType, ConstantStruct> StructConstantsTy; 272eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson StructConstantsTy StructConstants; 273006c77df8cc7f6a9dac575600b797b8ba32b29ebOwen Anderson 2742cb395eae71dacda49ca3fe758618fc3e0701659Talin typedef ConstantAggrUniqueMap<VectorType, ConstantVector> VectorConstantsTy; 275eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson VectorConstantsTy VectorConstants; 2765bd68393ed87bcedc53f5998f1af9c906f5a1b4eOwen Anderson 2779df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner DenseMap<PointerType*, ConstantPointerNull*> CPNConstants; 2789df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner 2799df0fb4e8176325d713ba4eb67791e36cb833432Chris Lattner DenseMap<Type*, UndefValue*> UVConstants; 2807e3142b0126abc86dc4da350e8b84b001c3eeddeOwen Anderson 28127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner StringMap<ConstantDataSequential*> CDSConstants; 28227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 28327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 2842ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses; 2852a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad ConstantUniqueMap<ExprMapKeyType, const ExprMapKeyType&, Type, ConstantExpr> 2862a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad ExprConstants; 287bf48a9b6db111fc14a8faef1adefbce5d807aaefJeffrey Yasskin 2882a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad ConstantUniqueMap<InlineAsmKeyType, const InlineAsmKeyType&, PointerType, 2892a4a6fecf0b8c92223f8fdf19545b564b7d3fcdeJay Foad InlineAsm> InlineAsms; 290d03eecd063a18ce0c505a87afcb04db26c035bc9Owen Anderson 291f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson ConstantInt *TheTrueVal; 292f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson ConstantInt *TheFalseVal; 293f53c371983908f02678b0e12c5d18466dcc70ffdOwen Anderson 294c34ebf65af0139eaf5cb0969fabcd32c0b6e1710Owen Anderson LeakDetectorImpl<Value> LLVMObjects; 295c34ebf65af0139eaf5cb0969fabcd32c0b6e1710Owen Anderson 29663a03cf58505aa839f721f212cd1518ebf133979Dan Gohman // Basic type instances. 297ce16339930a2b03e53b4e6399ef59c092a7f2cfaDan Gohman Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy; 2981afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; 2991afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty; 3009233b15d01ca62445bfc638f782243988c672e01Jeffrey Yasskin 301ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner 302ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner /// TypeAllocator - All dynamically allocated types are allocated from this. 303ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner /// They live forever until the context is torn down. 304ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner BumpPtrAllocator TypeAllocator; 305ba3ddf391f5149b8fca073adc3cbca361353929cChris Lattner 3061afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<unsigned, IntegerType*> IntegerTypes; 3071afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 308bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad typedef DenseMap<FunctionType*, bool, FunctionTypeKeyInfo> FunctionTypeMap; 309bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad FunctionTypeMap FunctionTypes; 310bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad typedef DenseMap<StructType*, bool, AnonStructTypeKeyInfo> StructTypeMap; 311bdf1748b12fa44b18b74ae71d68a9b964c4cb8c6Jay Foad StructTypeMap AnonStructTypes; 3121afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner StringMap<StructType*> NamedStructTypes; 3131afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner unsigned NamedStructTypesUniqueID; 3141afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 3151afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes; 3161afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes; 3171afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0 3181afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes; 3199233b15d01ca62445bfc638f782243988c672e01Jeffrey Yasskin 320ad715f86c90b06cc4ab9e1336d1bc3bf13ecb16dJeffrey Yasskin 3214d919438898d542850449235da7f6dc55e6ca152Owen Anderson /// ValueHandles - This map keeps track of all of the value handles that are 3224d919438898d542850449235da7f6dc55e6ca152Owen Anderson /// watching a Value*. The Value::HasValueHandle bit is used to know 3234d919438898d542850449235da7f6dc55e6ca152Owen Anderson // whether or not a value has an entry in this map. 3244d919438898d542850449235da7f6dc55e6ca152Owen Anderson typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy; 3254d919438898d542850449235da7f6dc55e6ca152Owen Anderson ValueHandlesTy ValueHandles; 3264d919438898d542850449235da7f6dc55e6ca152Owen Anderson 327081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// CustomMDKindNames - Map to hold the metadata string to ID mapping. 328081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner StringMap<unsigned> CustomMDKindNames; 329081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner 330081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner typedef std::pair<unsigned, TrackingVH<MDNode> > MDPairTy; 331081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner typedef SmallVector<MDPairTy, 2> MDMapTy; 332081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner 333081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// MetadataStore - Collection of per-instruction metadata used in this 334081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner /// context. 335081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner DenseMap<const Instruction *, MDMapTy> MetadataStore; 336081134741b40b342fb2f85722c9cea5d412489a8Chris Lattner 337b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeRecordIdx - This is the index in ScopeRecords for an MDNode scope 338b227925fa313428045f554187b0136d084d723f6Chris Lattner /// entry with no "inlined at" element. 339b227925fa313428045f554187b0136d084d723f6Chris Lattner DenseMap<MDNode*, int> ScopeRecordIdx; 340b227925fa313428045f554187b0136d084d723f6Chris Lattner 341b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeRecords - These are the actual mdnodes (in a value handle) for an 342b227925fa313428045f554187b0136d084d723f6Chris Lattner /// index. The ValueHandle ensures that ScopeRecordIdx stays up to date if 343b227925fa313428045f554187b0136d084d723f6Chris Lattner /// the MDNode is RAUW'd. 344b227925fa313428045f554187b0136d084d723f6Chris Lattner std::vector<DebugRecVH> ScopeRecords; 345b227925fa313428045f554187b0136d084d723f6Chris Lattner 346b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeInlinedAtIdx - This is the index in ScopeInlinedAtRecords for an 347b227925fa313428045f554187b0136d084d723f6Chris Lattner /// scope/inlined-at pair. 348b227925fa313428045f554187b0136d084d723f6Chris Lattner DenseMap<std::pair<MDNode*, MDNode*>, int> ScopeInlinedAtIdx; 349b227925fa313428045f554187b0136d084d723f6Chris Lattner 350b227925fa313428045f554187b0136d084d723f6Chris Lattner /// ScopeInlinedAtRecords - These are the actual mdnodes (in value handles) 351b227925fa313428045f554187b0136d084d723f6Chris Lattner /// for an index. The ValueHandle ensures that ScopeINlinedAtIdx stays up 352b227925fa313428045f554187b0136d084d723f6Chris Lattner /// to date. 353b227925fa313428045f554187b0136d084d723f6Chris Lattner std::vector<std::pair<DebugRecVH, DebugRecVH> > ScopeInlinedAtRecords; 354b227925fa313428045f554187b0136d084d723f6Chris Lattner 355b227925fa313428045f554187b0136d084d723f6Chris Lattner int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx); 356b227925fa313428045f554187b0136d084d723f6Chris Lattner int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx); 357b227925fa313428045f554187b0136d084d723f6Chris Lattner 3582f1efd639c8659582d0df2b8f927a018b057037fJeffrey Yasskin LLVMContextImpl(LLVMContext &C); 3592f1efd639c8659582d0df2b8f927a018b057037fJeffrey Yasskin ~LLVMContextImpl(); 3602bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson}; 3612bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson 3622bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson} 3632bc29dc0bcb3c1441477a062e4a5cffff175c8caOwen Anderson 3645217007006e91fa4bbfe88fde5149f5db293b247Owen Anderson#endif 365